Skip to content

Commit 4178d5d

Browse files
authored
fix(type): fix prop type infer (#4530)
fix #4525
1 parent 642710e commit 4178d5d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/runtime-core/src/componentProps.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +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>
112+
: [T] extends [(infer U)[] | { type: (infer U)[] }]
113+
? U extends DateConstructor
114+
? Date | InferPropType<U>
115+
: InferPropType<U>
116116
: [T] extends [Prop<infer V, infer D>]
117117
? unknown extends V
118118
? D

test-dts/defineComponent.test-d.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('with object props', () => {
4444
date?: Date
4545
l?: Date
4646
ll?: Date | number
47+
lll?: string | number
4748
}
4849

4950
type GT = string & { __brand: unknown }
@@ -135,7 +136,8 @@ describe('with object props', () => {
135136
},
136137
date: Date,
137138
l: [Date],
138-
ll: [Date, Number]
139+
ll: [Date, Number],
140+
lll: [String, Number]
139141
},
140142
setup(props) {
141143
// type assertion. See https://github.com/SamVerschueren/tsd
@@ -170,6 +172,7 @@ describe('with object props', () => {
170172
expectType<ExpectedProps['date']>(props.date)
171173
expectType<ExpectedProps['l']>(props.l)
172174
expectType<ExpectedProps['ll']>(props.ll)
175+
expectType<ExpectedProps['lll']>(props.lll)
173176

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

0 commit comments

Comments
 (0)