Skip to content

Commit 48f0d29

Browse files
authored
fix(types): extract the correct props type for the DateConstructor (#2676)
1 parent 288ae0a commit 48f0d29

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/runtime-core/src/componentProps.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ type InferPropType<T> = T extends null
9797
? Record<string, any>
9898
: T extends BooleanConstructor | { type: BooleanConstructor }
9999
? boolean
100-
: T extends Prop<infer V, infer D> ? (unknown extends V ? D : V) : T
100+
: T extends DateConstructor | { type: DateConstructor }
101+
? Date
102+
: T extends Prop<infer V, infer D> ? (unknown extends V ? D : V) : T
101103

102104
export type ExtractPropTypes<O> = O extends object
103105
? { [K in RequiredKeys<O>]: InferPropType<O[K]> } &

test-dts/defineComponent.test-d.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('with object props', () => {
3434
ggg: 'foo' | 'bar'
3535
ffff: (a: number, b: string) => { a: boolean }
3636
validated?: string
37+
date?: Date
3738
}
3839

3940
type GT = string & { __brand: unknown }
@@ -103,7 +104,8 @@ describe('with object props', () => {
103104
type: String,
104105
// validator requires explicit annotation
105106
validator: (val: unknown) => val !== ''
106-
}
107+
},
108+
date: Date
107109
},
108110
setup(props) {
109111
// type assertion. See https://github.com/SamVerschueren/tsd
@@ -125,6 +127,7 @@ describe('with object props', () => {
125127
expectType<ExpectedProps['ggg']>(props.ggg)
126128
expectType<ExpectedProps['ffff']>(props.ffff)
127129
expectType<ExpectedProps['validated']>(props.validated)
130+
expectType<ExpectedProps['date']>(props.date)
128131

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

0 commit comments

Comments
 (0)