@backland/schema
Version:
TypeScript schema declaration and validation library with static type inference
32 lines (31 loc) • 1.16 kB
TypeScript
import { Infer } from '../Infer';
import type { FieldDefinitionConfig } from '../TObjectConfig';
import { FieldType, FieldTypeParser } from './FieldType';
declare const validKeyTypes: readonly ["int", "string", "float"];
type ValidKeyType = typeof validKeyTypes[number];
export type RecordFieldDef = {
keyType?: ValidKeyType;
type?: FieldDefinitionConfig;
};
export type InferRecordFieldType<Def> = Def extends {
keyType: 'int' | 'float';
} ? {
[K: number]: Infer<Def extends {
type: FieldDefinitionConfig;
} ? Def['type'] : 'any'>;
} : {
[K: string]: Infer<Def extends {
type: FieldDefinitionConfig;
} ? Def['type'] : 'any'>;
};
export declare class RecordField<Def extends RecordFieldDef> extends FieldType<InferRecordFieldType<Def>, 'record', Def | undefined> {
__isRecordField: boolean;
static is(input: any): input is RecordField<RecordFieldDef>;
parse: FieldTypeParser<InferRecordFieldType<Def>>;
constructor(def?: Def);
static create: <Def_1 extends RecordFieldDef = {
keyType: 'string';
type: 'any';
}>(def?: Def_1 | undefined) => RecordField<Def_1>;
}
export {};