fix(types): extract the correct props type for the DateConstructor (#2676)
This commit is contained in:
parent
288ae0a8d9
commit
48f0d2944f
@ -97,6 +97,8 @@ type InferPropType<T> = T extends null
|
|||||||
? Record<string, any>
|
? Record<string, any>
|
||||||
: T extends BooleanConstructor | { type: BooleanConstructor }
|
: T extends BooleanConstructor | { type: BooleanConstructor }
|
||||||
? boolean
|
? boolean
|
||||||
|
: T extends DateConstructor | { type: DateConstructor }
|
||||||
|
? Date
|
||||||
: T extends Prop<infer V, infer D> ? (unknown extends V ? D : V) : T
|
: T extends Prop<infer V, infer D> ? (unknown extends V ? D : V) : T
|
||||||
|
|
||||||
export type ExtractPropTypes<O> = O extends object
|
export type ExtractPropTypes<O> = O extends object
|
||||||
|
@ -34,6 +34,7 @@ describe('with object props', () => {
|
|||||||
ggg: 'foo' | 'bar'
|
ggg: 'foo' | 'bar'
|
||||||
ffff: (a: number, b: string) => { a: boolean }
|
ffff: (a: number, b: string) => { a: boolean }
|
||||||
validated?: string
|
validated?: string
|
||||||
|
date?: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
type GT = string & { __brand: unknown }
|
type GT = string & { __brand: unknown }
|
||||||
@ -103,7 +104,8 @@ describe('with object props', () => {
|
|||||||
type: String,
|
type: String,
|
||||||
// validator requires explicit annotation
|
// validator requires explicit annotation
|
||||||
validator: (val: unknown) => val !== ''
|
validator: (val: unknown) => val !== ''
|
||||||
}
|
},
|
||||||
|
date: Date
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
// type assertion. See https://github.com/SamVerschueren/tsd
|
// type assertion. See https://github.com/SamVerschueren/tsd
|
||||||
@ -125,6 +127,7 @@ describe('with object props', () => {
|
|||||||
expectType<ExpectedProps['ggg']>(props.ggg)
|
expectType<ExpectedProps['ggg']>(props.ggg)
|
||||||
expectType<ExpectedProps['ffff']>(props.ffff)
|
expectType<ExpectedProps['ffff']>(props.ffff)
|
||||||
expectType<ExpectedProps['validated']>(props.validated)
|
expectType<ExpectedProps['validated']>(props.validated)
|
||||||
|
expectType<ExpectedProps['date']>(props.date)
|
||||||
|
|
||||||
// @ts-expect-error props should be readonly
|
// @ts-expect-error props should be readonly
|
||||||
expectError((props.a = 1))
|
expectError((props.a = 1))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user