Open phierru opened 1 year ago
This works:
export const isFieldRequired = (fieldName: string): boolean => {
const field = validationSchema.describe().fields[fieldName]
if (!field) throw new Error(`Field '${fieldName}' not found in schema`)
return (field as SchemaDescription).tests.some((test) => test.name === 'required')
}
TypeScript complains that property 'tests' does not exist on field but code runs fine.
To Reproduce
produces build error:
src/features/users/agents/model.ts:28:17 - error TS2339: Property 'tests' does not exist on type 'SchemaFieldDescription'. Property 'tests' does not exist on type 'SchemaRefDescription'. return (field.tests as Array<{ name: string }>).some((test) => test.name === 'required')
Expected behavior No error.
Platform typescript 5.1.6 vite 4.4.9