Skip to content

Commit 4645a42

Browse files
types(runtime-core): fix for multiple possible prop types including Date (#4518)
fix #4517
1 parent fac9a29 commit 4645a42

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/runtime-core/src/componentProps.ts

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ type InferPropType<T> = [T] extends [null]
109109
? boolean
110110
: [T] extends [DateConstructor | { type: DateConstructor }]
111111
? Date
112+
: [T] extends [
113+
(DateConstructor | infer U)[] | { type: (DateConstructor | infer U)[] }
114+
]
115+
? Date | InferPropType<U>
112116
: [T] extends [Prop<infer V, infer D>]
113117
? unknown extends V
114118
? D

test-dts/defineComponent.test-d.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ describe('with object props', () => {
4242
kkk?: any
4343
validated?: string
4444
date?: Date
45+
l?: Date
46+
ll?: Date | number
4547
}
4648

4749
type GT = string & { __brand: unknown }
@@ -131,7 +133,9 @@ describe('with object props', () => {
131133
// validator requires explicit annotation
132134
validator: (val: unknown) => val !== ''
133135
},
134-
date: Date
136+
date: Date,
137+
l: [Date],
138+
ll: [Date, Number]
135139
},
136140
setup(props) {
137141
// type assertion. See https://github.com/SamVerschueren/tsd
@@ -164,6 +168,8 @@ describe('with object props', () => {
164168
expectType<ExpectedProps['kkk']>(props.kkk)
165169
expectType<ExpectedProps['validated']>(props.validated)
166170
expectType<ExpectedProps['date']>(props.date)
171+
expectType<ExpectedProps['l']>(props.l)
172+
expectType<ExpectedProps['ll']>(props.ll)
167173

168174
// @ts-expect-error props should be readonly
169175
expectError((props.a = 1))

0 commit comments

Comments
 (0)