Typescript error for custom type in schema
I can's figure out how to correctly type schema fields when creating custom types. For example, I have the following field definition in my schema.
THUMBNAIL: {
prop: 'thumbnail',
required: true,
type: (value: string) => {
if (
!value.toLowerCase().endsWith('.gif') &&
!value.toLowerCase().endsWith('.jpg') &&
!value.toLowerCase().endsWith('.jpeg') &&
!value.toLowerCase().endsWith('.png') &&
!value.toLowerCase().endsWith('.webp')
) {
throw new Error(
'Invalid thumbnail file type. Must be gif, jpg, jpeg, png, or webp'
);
}
return value;
},
},
This works as expected and returns an error if the filetype is wrong. However, Typescript is throwing the following error:
No overload matches this call.
Overload 1 of 3, '(input: File, options: ParseWithSchemaOptions<object>): Promise<ParsedObjectsResult<object>>', gave the following error.
Type '{ AGE_DEMOGRAPHIC_FROM: { prop: string; type: NumberConstructor; }; AGE_DEMOGRAPHIC_TO: { prop: string; type: NumberConstructor; }; IMPRINT: { prop: string; type: StringConstructor; }; ... 9 more ...; TITLE: { ...; }; }' is not assignable to type 'Schema'.
Property 'THUMBNAIL' is incompatible with index signature.
Type '{ prop: string; required: boolean; type: (value: string) => string; }' is not assignable to type 'SchemaEntry'.
Type '{ prop: string; required: boolean; type: (value: string) => string; }' is not assignable to type 'SchemaEntryRecursive'.
Types of property 'type' are incompatible.
Type '(value: string) => string' is not assignable to type 'Record<string, SchemaEntry>'.
Index signature for type 'string' is missing in type '(value: string) => string'.
Overload 2 of 3, '(input: File, options: ParseWithMapOptions): Promise<ParsedObjectsResult<object>>', gave the following error.
Argument of type '{ schema: { AGE_DEMOGRAPHIC_FROM: { prop: string; type: NumberConstructor; }; AGE_DEMOGRAPHIC_TO: { prop: string; type: NumberConstructor; }; IMPRINT: { ...; }; ... 9 more ...; TITLE: { ...; }; }; }' is not assignable to parameter of type 'ParseWithMapOptions'.
Object literal may only specify known properties, and 'schema' does not exist in type 'ParseWithMapOptions'.
Overload 3 of 3, '(input: File, options?: ParseWithoutSchemaOptions | undefined): Promise<Row[]>', gave the following error.
Argument of type '{ schema: { AGE_DEMOGRAPHIC_FROM: { prop: string; type: NumberConstructor; }; AGE_DEMOGRAPHIC_TO: { prop: string; type: NumberConstructor; }; IMPRINT: { ...; }; ... 9 more ...; TITLE: { ...; }; }; }' is not assignable to parameter of type 'ParseWithoutSchemaOptions'.
Object literal may only specify known properties, and 'schema' does not exist in type 'ParseWithoutSchemaOptions'.ts(2769)
types.d.ts(67, 2): The expected type comes from property 'schema' which is declared here on type 'ParseWithSchemaOptions<object>'
Is there something else I should be doing or is this an issue?
Edited by Greg Mascherino