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> | 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> { | interface PropOptions<T = any, D = T> { | ||||||
|   type?: PropType<T> | true | null |   type?: PropType<T> | true | null | ||||||
|  | |||||||
| @ -18,6 +18,7 @@ describe('with object props', () => { | |||||||
|     b: string |     b: string | ||||||
|     e?: Function |     e?: Function | ||||||
|     bb: string |     bb: string | ||||||
|  |     bbb: string | ||||||
|     cc?: string[] | undefined |     cc?: string[] | undefined | ||||||
|     dd: { n: 1 } |     dd: { n: 1 } | ||||||
|     ee?: () => string |     ee?: () => string | ||||||
| @ -46,6 +47,11 @@ describe('with object props', () => { | |||||||
|       bb: { |       bb: { | ||||||
|         default: 'hello' |         default: 'hello' | ||||||
|       }, |       }, | ||||||
|  |       bbb: { | ||||||
|  |         // Note: default function value requires arrow syntax + explicit
 | ||||||
|  |         // annotation
 | ||||||
|  |         default: (props: any) => (props.bb as string) || 'foo' | ||||||
|  |       }, | ||||||
|       // explicit type casting
 |       // explicit type casting
 | ||||||
|       cc: Array as PropType<string[]>, |       cc: Array as PropType<string[]>, | ||||||
|       // required + type casting
 |       // required + type casting
 | ||||||
| @ -85,6 +91,7 @@ describe('with object props', () => { | |||||||
|       }, |       }, | ||||||
|       validated: { |       validated: { | ||||||
|         type: String, |         type: String, | ||||||
|  |         // validator requires explicit annotation
 | ||||||
|         validator: (val: unknown) => val !== '' |         validator: (val: unknown) => val !== '' | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| @ -94,6 +101,7 @@ describe('with object props', () => { | |||||||
|       expectType<ExpectedProps['b']>(props.b) |       expectType<ExpectedProps['b']>(props.b) | ||||||
|       expectType<ExpectedProps['e']>(props.e) |       expectType<ExpectedProps['e']>(props.e) | ||||||
|       expectType<ExpectedProps['bb']>(props.bb) |       expectType<ExpectedProps['bb']>(props.bb) | ||||||
|  |       expectType<ExpectedProps['bbb']>(props.bbb) | ||||||
|       expectType<ExpectedProps['cc']>(props.cc) |       expectType<ExpectedProps['cc']>(props.cc) | ||||||
|       expectType<ExpectedProps['dd']>(props.dd) |       expectType<ExpectedProps['dd']>(props.dd) | ||||||
|       expectType<ExpectedProps['ee']>(props.ee) |       expectType<ExpectedProps['ee']>(props.ee) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user