]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(dx): improve readability of displayed types for props
authorEvan You <yyx990803@gmail.com>
Fri, 24 Mar 2023 07:06:43 +0000 (15:06 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 24 Mar 2023 07:06:43 +0000 (15:06 +0800)
packages/runtime-core/src/apiSetupHelpers.ts
packages/runtime-core/src/componentOptions.ts
packages/runtime-core/src/componentPublicInstance.ts
packages/shared/src/typeUtils.ts

index 798b3a0c0005aa5398424cb8dc7e2f13db420ae2..882e0389c97c6473f2a5fb86e2257d5675761adc 100644 (file)
@@ -1,4 +1,4 @@
-import { isArray, isPromise, isFunction } from '@vue/shared'
+import { isArray, isPromise, isFunction, Prettify } from '@vue/shared'
 import {
   getCurrentInstance,
   setCurrentInstance,
@@ -55,18 +55,20 @@ const warnRuntimeUsage = (method: string) =>
 // overload 1: runtime props w/ array
 export function defineProps<PropNames extends string = string>(
   props: PropNames[]
-): Readonly<{ [key in PropNames]?: any }>
+): Prettify<Readonly<{ [key in PropNames]?: any }>>
 // overload 2: runtime props w/ object
 export function defineProps<
   PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions
->(props: PP): Readonly<ExtractPropTypes<PP>>
+>(props: PP): Prettify<Readonly<ExtractPropTypes<PP>>>
 // overload 3: typed-based declaration
-export function defineProps<TypeProps>(): Readonly<
-  Omit<TypeProps, BooleanKey<TypeProps>> & {
-    [K in keyof Pick<TypeProps, BooleanKey<TypeProps>>]-?: NotUndefined<
-      TypeProps[K]
-    >
-  }
+export function defineProps<TypeProps>(): Prettify<
+  Readonly<
+    Omit<TypeProps, BooleanKey<TypeProps>> & {
+      [K in keyof Pick<TypeProps, BooleanKey<TypeProps>>]-?: NotUndefined<
+        TypeProps[K]
+      >
+    }
+  >
 >
 // implementation
 export function defineProps() {
index 956db272ed0247dfe7fa0a7c9b9bd2d7137cc5a4..b5324c80dd07e8c8df88645a81f7a25b3a1c89fa 100644 (file)
@@ -15,7 +15,8 @@ import {
   isArray,
   NOOP,
   isPromise,
-  LooseRequired
+  LooseRequired,
+  Prettify
 } from '@vue/shared'
 import { isRef, Ref } from '@vue/reactivity'
 import { computed } from './apiComputed'
@@ -112,14 +113,14 @@ export interface ComponentOptionsBase<
     ComponentCustomOptions {
   setup?: (
     this: void,
-    props: Readonly<
-      LooseRequired<
-        Props &
+    props: LooseRequired<
+      Props &
+        Prettify<
           UnwrapMixinsType<
             IntersectionMixin<Mixin> & IntersectionMixin<Extends>,
             'P'
           >
-      >
+        >
     >,
     ctx: SetupContext<E>
   ) => Promise<RawBindings> | RawBindings | RenderFunction | void
@@ -262,7 +263,7 @@ export type ComponentOptionsWithArrayProps<
   EE extends string = string,
   I extends ComponentInjectOptions = {},
   II extends string = string,
-  Props = Readonly<{ [key in PropNames]?: any }> & EmitsToProps<E>
+  Props = Prettify<Readonly<{ [key in PropNames]?: any } & EmitsToProps<E>>>
 > = ComponentOptionsBase<
   Props,
   RawBindings,
@@ -307,7 +308,7 @@ export type ComponentOptionsWithObjectProps<
   EE extends string = string,
   I extends ComponentInjectOptions = {},
   II extends string = string,
-  Props = Readonly<ExtractPropTypes<PropsOptions>> & EmitsToProps<E>,
+  Props = Prettify<Readonly<ExtractPropTypes<PropsOptions> & EmitsToProps<E>>>,
   Defaults = ExtractDefaultPropTypes<PropsOptions>
 > = ComponentOptionsBase<
   Props,
index 61a0e01324d4a1fb9abf09fd47f4665bc51a946f..f083f06205253a4e856b4596537d1d539082d1cc 100644 (file)
@@ -14,7 +14,8 @@ import {
   extend,
   isString,
   isFunction,
-  UnionToIntersection
+  UnionToIntersection,
+  Prettify
 } from '@vue/shared'
 import {
   toRaw,
@@ -185,9 +186,11 @@ export type ComponentPublicInstance<
 > = {
   $: ComponentInternalInstance
   $data: D
-  $props: MakeDefaultsOptional extends true
-    ? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
-    : P & PublicProps
+  $props: Prettify<
+    MakeDefaultsOptional extends true
+      ? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
+      : P & PublicProps
+  >
   $attrs: Data
   $refs: Data
   $slots: Slots
index 0d767469b4d6ee2715ea263a3015db11aa83a312..67fb47c23b3a1aff358d09e5791266255ced66a4 100644 (file)
@@ -1,3 +1,5 @@
+export type Prettify<T> = { [K in keyof T]: T[K] } & {}
+
 export type UnionToIntersection<U> = (
   U extends any ? (k: U) => void : never
 ) extends (k: infer I) => void