export type Prop<T, D = T> = PropOptions<T, D> | PropType<T>
-type DefaultFactory<T> = () => T | null | undefined
+type DefaultFactory<T> = (props: Data) => T | null | undefined
interface PropOptions<T = any, D = T> {
type?: PropType<T> | true | null
b: string
e?: Function
bb: string
+ bbb: string
cc?: string[] | undefined
dd: { n: 1 }
ee?: () => string
bb: {
default: 'hello'
},
+ bbb: {
+ // Note: default function value requires arrow syntax + explicit
+ // annotation
+ default: (props: any) => (props.bb as string) || 'foo'
+ },
// explicit type casting
cc: Array as PropType<string[]>,
// required + type casting
},
validated: {
type: String,
+ // validator requires explicit annotation
validator: (val: unknown) => val !== ''
}
},
expectType<ExpectedProps['b']>(props.b)
expectType<ExpectedProps['e']>(props.e)
expectType<ExpectedProps['bb']>(props.bb)
+ expectType<ExpectedProps['bbb']>(props.bbb)
expectType<ExpectedProps['cc']>(props.cc)
expectType<ExpectedProps['dd']>(props.dd)
expectType<ExpectedProps['ee']>(props.ee)