Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(type): fix prop type infer #4530

Merged
merged 2 commits into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/runtime-core/src/componentProps.ts
Expand Up @@ -109,10 +109,10 @@ type InferPropType<T> = [T] extends [null]
? boolean
: [T] extends [DateConstructor | { type: DateConstructor }]
? Date
: [T] extends [
(DateConstructor | infer U)[] | { type: (DateConstructor | infer U)[] }
]
? Date | InferPropType<U>
: [T] extends [(infer U)[] | { type: (infer U)[] }]
? U extends DateConstructor
? Date | InferPropType<U>
: InferPropType<U>
: [T] extends [Prop<infer V, infer D>]
? unknown extends V
? D
Expand Down
5 changes: 4 additions & 1 deletion test-dts/defineComponent.test-d.tsx
Expand Up @@ -44,6 +44,7 @@ describe('with object props', () => {
date?: Date
l?: Date
ll?: Date | number
lll?: string | number
}

type GT = string & { __brand: unknown }
Expand Down Expand Up @@ -135,7 +136,8 @@ describe('with object props', () => {
},
date: Date,
l: [Date],
ll: [Date, Number]
ll: [Date, Number],
lll: [String, Number]
},
setup(props) {
// type assertion. See https://github.com/SamVerschueren/tsd
Expand Down Expand Up @@ -170,6 +172,7 @@ describe('with object props', () => {
expectType<ExpectedProps['date']>(props.date)
expectType<ExpectedProps['l']>(props.l)
expectType<ExpectedProps['ll']>(props.ll)
expectType<ExpectedProps['lll']>(props.lll)

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