From 413a99e501caa55773763c4767620b7fb4f86a19 Mon Sep 17 00:00:00 2001 From: HcySunYang Date: Fri, 27 Nov 2020 14:48:17 +0800 Subject: [PATCH 1/2] fix(types): extract the correct props type for the DateConstructor --- packages/runtime-core/src/componentProps.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 47b06459505..c42c0f82639 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -97,7 +97,9 @@ type InferPropType = T extends null ? Record : T extends BooleanConstructor | { type: BooleanConstructor } ? boolean - : T extends Prop ? (unknown extends V ? D : V) : T + : T extends DateConstructor | { type: DateConstructor } + ? Date + : T extends Prop ? (unknown extends V ? D : V) : T export type ExtractPropTypes = O extends object ? { [K in RequiredKeys]: InferPropType } & From 7241ed5e68f2a394bc02aca601e0a4ef9bd93a35 Mon Sep 17 00:00:00 2001 From: HcySunYang Date: Fri, 27 Nov 2020 17:57:28 +0800 Subject: [PATCH 2/2] test: prop of type Date --- test-dts/defineComponent.test-d.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index c77feba025d..b22b6456e12 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -34,6 +34,7 @@ describe('with object props', () => { ggg: 'foo' | 'bar' ffff: (a: number, b: string) => { a: boolean } validated?: string + date?: Date } type GT = string & { __brand: unknown } @@ -103,7 +104,8 @@ describe('with object props', () => { type: String, // validator requires explicit annotation validator: (val: unknown) => val !== '' - } + }, + date: Date }, setup(props) { // type assertion. See https://github.com/SamVerschueren/tsd @@ -125,6 +127,7 @@ describe('with object props', () => { expectType(props.ggg) expectType(props.ffff) expectType(props.validated) + expectType(props.date) // @ts-expect-error props should be readonly expectError((props.a = 1))