diff --git a/packages/zero-schema/src/column.ts b/packages/zero-schema/src/column.ts index ca5d96ed1..b1a015eb4 100644 --- a/packages/zero-schema/src/column.ts +++ b/packages/zero-schema/src/column.ts @@ -1,43 +1,142 @@ -export function string(optional: boolean = false) { +export function string(): { + type: 'string'; + optional: false; + customType: T; +}; +export function string( + optional: false, +): { + type: 'string'; + optional: false; + customType: T; +}; +export function string( + optional: true, +): { + type: 'string'; + optional: true; + customType: T; +}; +export function string(optional?: boolean) { return { type: 'string', - optional, + optional: optional ?? false, customType: null as unknown as T, } as const; } -export function number(optional: boolean = false) { +export function number(): { + type: 'number'; + optional: false; + customType: T; +}; +export function number( + optional: false, +): { + type: 'number'; + optional: false; + customType: T; +}; +export function number( + optional: true, +): { + type: 'number'; + optional: true; + customType: T; +}; +export function number(optional?: boolean) { return { type: 'number', - optional, + optional: optional ?? false, customType: null as unknown as T, } as const; } +export function boolean(): { + type: 'boolean'; + optional: false; + customType: T; +}; export function boolean( - optional: boolean = false, -) { + optional: false, +): { + type: 'boolean'; + optional: false; + customType: T; +}; +export function boolean( + optional: true, +): { + type: 'boolean'; + optional: true; + customType: T; +}; +export function boolean(optional?: boolean) { return { type: 'boolean', - optional, + optional: optional ?? false, customType: null as unknown as T, } as const; } // eslint-disable-next-line @typescript-eslint/no-explicit-any -export function json(optional: boolean = false) { +export function json(): { + type: 'json'; + optional: false; + customType: T; +}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function json( + optional: false, +): { + type: 'json'; + optional: false; + customType: T; +}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function json( + optional: true, +): { + type: 'json'; + optional: true; + customType: T; +}; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function json(optional?: boolean) { return { type: 'json', - optional, + optional: optional ?? false, customType: null as unknown as T, } as const; } -export function enumeration(optional: boolean = false) { +export function enumeration(): { + type: 'string'; + kind: 'enum'; + optional: false; + customType: T; +}; +export function enumeration( + optional: false, +): { + type: 'string'; + kind: 'enum'; + optional: false; + customType: T; +}; +export function enumeration( + optional: true, +): { + type: 'string'; + kind: 'enum'; + optional: true; + customType: T; +}; +export function enumeration(optional?: boolean) { return { type: 'string', kind: 'enum', customType: null as unknown as T, - optional, + optional: optional ?? false, } as const; }