From d78b6d2ca72df874e458d51c5b4f173ed26030da Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Fri, 24 Dec 2021 17:53:50 +0800 Subject: [PATCH 1/3] feat(types): fix renaming not working for props --- packages/runtime-core/src/componentProps.ts | 10 +++++++--- packages/runtime-core/src/helpers/typeUtils.ts | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index cf73261fc51..38389921410 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -121,9 +121,13 @@ type InferPropType = [T] extends [null] : T export type ExtractPropTypes = O extends object - ? { [K in keyof O]?: unknown } & // This is needed to keep the relation between the option prop and the props, allowing to use ctrl+click to navigate to the prop options. see: #3656 - { [K in RequiredKeys]: InferPropType } & - { [K in OptionalKeys]?: InferPropType } + ? { + // use `keyof Pick>` instead of `RequiredKeys` to support IDE features + [K in keyof Pick>]: InferPropType + } & { + // use `keyof Pick>` instead of `OptionalKeys` to support IDE features + [K in keyof Pick>]?: InferPropType + } : { [K in string]: any } const enum BooleanFlags { diff --git a/packages/runtime-core/src/helpers/typeUtils.ts b/packages/runtime-core/src/helpers/typeUtils.ts index 8caba54c6ca..bbb86e3aebd 100644 --- a/packages/runtime-core/src/helpers/typeUtils.ts +++ b/packages/runtime-core/src/helpers/typeUtils.ts @@ -5,6 +5,7 @@ export type UnionToIntersection = ( : never // make keys required but keep undefined values -export type LooseRequired = { [P in string & keyof T]: T[P] } +// use `keyof Pick` instead of `string & keyof T` to support IDE features +export type LooseRequired = { [P in keyof Pick]: T[P] } export type IfAny = 0 extends (1 & T) ? Y : N From c2db1d4c1b691e6959e7af8f3b6c84257459cfc1 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Fri, 24 Dec 2021 17:56:55 +0800 Subject: [PATCH 2/3] feat(types): avoid props JSDocs being removed --- packages/runtime-core/src/componentProps.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 38389921410..dbd5453904d 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -120,15 +120,13 @@ type InferPropType = [T] extends [null] : V : T -export type ExtractPropTypes = O extends object - ? { - // use `keyof Pick>` instead of `RequiredKeys` to support IDE features - [K in keyof Pick>]: InferPropType - } & { - // use `keyof Pick>` instead of `OptionalKeys` to support IDE features - [K in keyof Pick>]?: InferPropType - } - : { [K in string]: any } +export type ExtractPropTypes = { + // use `keyof Pick>` instead of `RequiredKeys` to support IDE features + [K in keyof Pick>]: InferPropType +} & { + // use `keyof Pick>` instead of `OptionalKeys` to support IDE features + [K in keyof Pick>]?: InferPropType +} const enum BooleanFlags { shouldCast, From e5c9c8f2d1e2780abd17474f183f7ebdc6f8c8af Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Sat, 25 Dec 2021 00:33:22 +0800 Subject: [PATCH 3/3] feat(types): fix `LooseRequired` not working --- packages/runtime-core/src/helpers/typeUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/runtime-core/src/helpers/typeUtils.ts b/packages/runtime-core/src/helpers/typeUtils.ts index bbb86e3aebd..8caba54c6ca 100644 --- a/packages/runtime-core/src/helpers/typeUtils.ts +++ b/packages/runtime-core/src/helpers/typeUtils.ts @@ -5,7 +5,6 @@ export type UnionToIntersection = ( : never // make keys required but keep undefined values -// use `keyof Pick` instead of `string & keyof T` to support IDE features -export type LooseRequired = { [P in keyof Pick]: T[P] } +export type LooseRequired = { [P in string & keyof T]: T[P] } export type IfAny = 0 extends (1 & T) ? Y : N