types(props): Support undefined
as default (#3783)
This commit is contained in:
parent
47da92146c
commit
92e7330385
@ -76,7 +76,7 @@ type RequiredKeys<T> = {
|
|||||||
// don't mark Boolean props as undefined
|
// don't mark Boolean props as undefined
|
||||||
| BooleanConstructor
|
| BooleanConstructor
|
||||||
| { type: BooleanConstructor }
|
| { type: BooleanConstructor }
|
||||||
? K
|
? T[K] extends { default: undefined | (() => undefined) } ? never : K
|
||||||
: never
|
: never
|
||||||
}[keyof T]
|
}[keyof T]
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ describe('with object props', () => {
|
|||||||
h: boolean
|
h: boolean
|
||||||
bb: string
|
bb: string
|
||||||
bbb: string
|
bbb: string
|
||||||
|
bbbb: string | undefined
|
||||||
|
bbbbb: string | undefined
|
||||||
cc?: string[] | undefined
|
cc?: string[] | undefined
|
||||||
dd: { n: 1 }
|
dd: { n: 1 }
|
||||||
ee?: () => string
|
ee?: () => string
|
||||||
@ -62,6 +64,14 @@ describe('with object props', () => {
|
|||||||
// annotation
|
// annotation
|
||||||
default: (props: any) => (props.bb as string) || 'foo'
|
default: (props: any) => (props.bb as string) || 'foo'
|
||||||
},
|
},
|
||||||
|
bbbb: {
|
||||||
|
type: String,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
|
bbbbb: {
|
||||||
|
type: String,
|
||||||
|
default: () => undefined
|
||||||
|
},
|
||||||
// explicit type casting
|
// explicit type casting
|
||||||
cc: Array as PropType<string[]>,
|
cc: Array as PropType<string[]>,
|
||||||
// required + type casting
|
// required + type casting
|
||||||
@ -129,6 +139,8 @@ describe('with object props', () => {
|
|||||||
expectType<ExpectedProps['h']>(props.h)
|
expectType<ExpectedProps['h']>(props.h)
|
||||||
expectType<ExpectedProps['bb']>(props.bb)
|
expectType<ExpectedProps['bb']>(props.bb)
|
||||||
expectType<ExpectedProps['bbb']>(props.bbb)
|
expectType<ExpectedProps['bbb']>(props.bbb)
|
||||||
|
expectType<ExpectedProps['bbbb']>(props.bbbb)
|
||||||
|
expectType<ExpectedProps['bbbbb']>(props.bbbbb)
|
||||||
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…
Reference in New Issue
Block a user