interface PropOptions<T = any, D = T> {
type?: PropType<T> | true | null
required?: boolean
- default?: D | DefaultFactory<D> | null | undefined
+ default?: D | DefaultFactory<D> | null | undefined | object
validator?(value: unknown): boolean
}
fff: (a: number, b: string) => { a: boolean }
hhh: boolean
ggg: 'foo' | 'bar'
+ ffff: (a: number, b: string) => { a: boolean }
validated?: string
}
type: String as PropType<'foo' | 'bar'>,
default: 'foo'
},
+ // default + function
+ ffff: {
+ type: Function as PropType<(a: number, b: string) => { a: boolean }>,
+ default: (a: number, b: string) => ({ a: true })
+ },
validated: {
type: String,
// validator requires explicit annotation
expectType<ExpectedProps['fff']>(props.fff)
expectType<ExpectedProps['hhh']>(props.hhh)
expectType<ExpectedProps['ggg']>(props.ggg)
+ expectType<ExpectedProps['ffff']>(props.ffff)
expectType<ExpectedProps['validated']>(props.validated)
// @ts-expect-error props should be readonly