Skip to content

Commit 92e7330

Browse files
authored
types(props): Support undefined as default (vuejs#3783)
1 parent 47da921 commit 92e7330

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/runtime-core/src/componentProps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type RequiredKeys<T> = {
7676
// don't mark Boolean props as undefined
7777
| BooleanConstructor
7878
| { type: BooleanConstructor }
79-
? K
79+
? T[K] extends { default: undefined | (() => undefined) } ? never : K
8080
: never
8181
}[keyof T]
8282

test-dts/defineComponent.test-d.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ describe('with object props', () => {
2323
h: boolean
2424
bb: string
2525
bbb: string
26+
bbbb: string | undefined
27+
bbbbb: string | undefined
2628
cc?: string[] | undefined
2729
dd: { n: 1 }
2830
ee?: () => string
@@ -62,6 +64,14 @@ describe('with object props', () => {
6264
// annotation
6365
default: (props: any) => (props.bb as string) || 'foo'
6466
},
67+
bbbb: {
68+
type: String,
69+
default: undefined
70+
},
71+
bbbbb: {
72+
type: String,
73+
default: () => undefined
74+
},
6575
// explicit type casting
6676
cc: Array as PropType<string[]>,
6777
// required + type casting
@@ -129,6 +139,8 @@ describe('with object props', () => {
129139
expectType<ExpectedProps['h']>(props.h)
130140
expectType<ExpectedProps['bb']>(props.bb)
131141
expectType<ExpectedProps['bbb']>(props.bbb)
142+
expectType<ExpectedProps['bbbb']>(props.bbbb)
143+
expectType<ExpectedProps['bbbbb']>(props.bbbbb)
132144
expectType<ExpectedProps['cc']>(props.cc)
133145
expectType<ExpectedProps['dd']>(props.dd)
134146
expectType<ExpectedProps['ee']>(props.ee)

0 commit comments

Comments
 (0)