types(runtime-core): argument for props validator
Unfortunately it requires explicit annotation for now
This commit is contained in:
parent
a88895b5da
commit
9f92871c80
@ -42,7 +42,7 @@ export type ComponentObjectPropsOptions<P = Data> = {
|
||||
|
||||
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
|
||||
|
@ -18,6 +18,7 @@ describe('with object props', () => {
|
||||
b: string
|
||||
e?: Function
|
||||
bb: string
|
||||
bbb: string
|
||||
cc?: string[] | undefined
|
||||
dd: { n: 1 }
|
||||
ee?: () => string
|
||||
@ -46,6 +47,11 @@ describe('with object props', () => {
|
||||
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
|
||||
@ -85,6 +91,7 @@ describe('with object props', () => {
|
||||
},
|
||||
validated: {
|
||||
type: String,
|
||||
// validator requires explicit annotation
|
||||
validator: (val: unknown) => val !== ''
|
||||
}
|
||||
},
|
||||
@ -94,6 +101,7 @@ describe('with object props', () => {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user