]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(types): simplify `ExtractPropTypes` to avoid props JSDocs being removed (#5166)
authorJohnson Chu <johnsoncodehk@gmail.com>
Sat, 25 Dec 2021 07:52:22 +0000 (15:52 +0800)
committerGitHub <noreply@github.com>
Sat, 25 Dec 2021 07:52:22 +0000 (02:52 -0500)
packages/runtime-core/src/componentProps.ts

index cf73261fc51ae0db1b21019abf8d9c08748480d0..dbd5453904d8c463222785ea78bf6c067e691700 100644 (file)
@@ -120,11 +120,13 @@ type InferPropType<T> = [T] extends [null]
     : V
   : T
 
-export type ExtractPropTypes<O> = 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<O>]: InferPropType<O[K]> } &
-      { [K in OptionalKeys<O>]?: InferPropType<O[K]> }
-  : { [K in string]: any }
+export type ExtractPropTypes<O> = {
+  // use `keyof Pick<O, RequiredKeys<O>>` instead of `RequiredKeys<O>` to support IDE features
+  [K in keyof Pick<O, RequiredKeys<O>>]: InferPropType<O[K]>
+} & {
+  // use `keyof Pick<O, OptionalKeys<O>>` instead of `OptionalKeys<O>` to support IDE features
+  [K in keyof Pick<O, OptionalKeys<O>>]?: InferPropType<O[K]>
+}
 
 const enum BooleanFlags {
   shouldCast,