Skip to content

Commit b2acb2d

Browse files
authored
fix: Date infer string in props (#627)
1 parent 5301d49 commit b2acb2d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/component/componentProps.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ type InferPropType<T> = T extends null
5151
? Record<string, any>
5252
: T extends BooleanConstructor | { type: BooleanConstructor }
5353
? boolean
54-
: T extends FunctionConstructor
55-
? Function
56-
: T extends Prop<infer V, infer D>
57-
? unknown extends V
58-
? D
59-
: ExtractCorrectPropType<V>
60-
: T
54+
: T extends DateConstructor | { type: DateConstructor}
55+
? Date
56+
: T extends FunctionConstructor
57+
? Function
58+
: T extends Prop<infer V, infer D>
59+
? unknown extends V
60+
? D
61+
: ExtractCorrectPropType<V>
62+
: T
6163

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

test-dts/defineComponent.test-d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('with object props', () => {
2727
ggg: 'foo' | 'bar'
2828
ffff: (a: number, b: string) => { a: boolean }
2929
validated?: string
30+
date: Date
3031
}
3132

3233
type GT = string & { __brand: unknown }
@@ -96,6 +97,10 @@ describe('with object props', () => {
9697
// validator requires explicit annotation
9798
validator: (val: unknown) => val !== '',
9899
},
100+
date: {
101+
type: Date,
102+
required: true,
103+
},
99104
},
100105
setup(props) {
101106
// type assertion. See https://github.com/SamVerschueren/tsd
@@ -116,6 +121,7 @@ describe('with object props', () => {
116121
expectType<ExpectedProps['hhh']>(props.hhh)
117122
expectType<ExpectedProps['ffff']>(props.ffff)
118123
expectType<ExpectedProps['validated']>(props.validated)
124+
expectType<ExpectedProps['date']>(props.date)
119125

120126
isNotAnyOrUndefined(props.a)
121127
isNotAnyOrUndefined(props.b)

0 commit comments

Comments
 (0)