Skip to content

Commit 4c9bfd2

Browse files
committed
feat(dx): improve readability of displayed types for props
1 parent 58e5c51 commit 4c9bfd2

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

packages/runtime-core/src/apiSetupHelpers.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray, isPromise, isFunction } from '@vue/shared'
1+
import { isArray, isPromise, isFunction, Prettify } from '@vue/shared'
22
import {
33
getCurrentInstance,
44
setCurrentInstance,
@@ -55,18 +55,20 @@ const warnRuntimeUsage = (method: string) =>
5555
// overload 1: runtime props w/ array
5656
export function defineProps<PropNames extends string = string>(
5757
props: PropNames[]
58-
): Readonly<{ [key in PropNames]?: any }>
58+
): Prettify<Readonly<{ [key in PropNames]?: any }>>
5959
// overload 2: runtime props w/ object
6060
export function defineProps<
6161
PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions
62-
>(props: PP): Readonly<ExtractPropTypes<PP>>
62+
>(props: PP): Prettify<Readonly<ExtractPropTypes<PP>>>
6363
// overload 3: typed-based declaration
64-
export function defineProps<TypeProps>(): Readonly<
65-
Omit<TypeProps, BooleanKey<TypeProps>> & {
66-
[K in keyof Pick<TypeProps, BooleanKey<TypeProps>>]-?: NotUndefined<
67-
TypeProps[K]
68-
>
69-
}
64+
export function defineProps<TypeProps>(): Prettify<
65+
Readonly<
66+
Omit<TypeProps, BooleanKey<TypeProps>> & {
67+
[K in keyof Pick<TypeProps, BooleanKey<TypeProps>>]-?: NotUndefined<
68+
TypeProps[K]
69+
>
70+
}
71+
>
7072
>
7173
// implementation
7274
export function defineProps() {

packages/runtime-core/src/componentOptions.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
isArray,
1616
NOOP,
1717
isPromise,
18-
LooseRequired
18+
LooseRequired,
19+
Prettify
1920
} from '@vue/shared'
2021
import { isRef, Ref } from '@vue/reactivity'
2122
import { computed } from './apiComputed'
@@ -112,14 +113,14 @@ export interface ComponentOptionsBase<
112113
ComponentCustomOptions {
113114
setup?: (
114115
this: void,
115-
props: Readonly<
116-
LooseRequired<
117-
Props &
116+
props: LooseRequired<
117+
Props &
118+
Prettify<
118119
UnwrapMixinsType<
119120
IntersectionMixin<Mixin> & IntersectionMixin<Extends>,
120121
'P'
121122
>
122-
>
123+
>
123124
>,
124125
ctx: SetupContext<E>
125126
) => Promise<RawBindings> | RawBindings | RenderFunction | void
@@ -262,7 +263,7 @@ export type ComponentOptionsWithArrayProps<
262263
EE extends string = string,
263264
I extends ComponentInjectOptions = {},
264265
II extends string = string,
265-
Props = Readonly<{ [key in PropNames]?: any }> & EmitsToProps<E>
266+
Props = Prettify<Readonly<{ [key in PropNames]?: any } & EmitsToProps<E>>>
266267
> = ComponentOptionsBase<
267268
Props,
268269
RawBindings,
@@ -307,7 +308,7 @@ export type ComponentOptionsWithObjectProps<
307308
EE extends string = string,
308309
I extends ComponentInjectOptions = {},
309310
II extends string = string,
310-
Props = Readonly<ExtractPropTypes<PropsOptions>> & EmitsToProps<E>,
311+
Props = Prettify<Readonly<ExtractPropTypes<PropsOptions> & EmitsToProps<E>>>,
311312
Defaults = ExtractDefaultPropTypes<PropsOptions>
312313
> = ComponentOptionsBase<
313314
Props,

packages/runtime-core/src/componentPublicInstance.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
extend,
1515
isString,
1616
isFunction,
17-
UnionToIntersection
17+
UnionToIntersection,
18+
Prettify
1819
} from '@vue/shared'
1920
import {
2021
toRaw,
@@ -185,9 +186,11 @@ export type ComponentPublicInstance<
185186
> = {
186187
$: ComponentInternalInstance
187188
$data: D
188-
$props: MakeDefaultsOptional extends true
189-
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
190-
: P & PublicProps
189+
$props: Prettify<
190+
MakeDefaultsOptional extends true
191+
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
192+
: P & PublicProps
193+
>
191194
$attrs: Data
192195
$refs: Data
193196
$slots: Slots

packages/shared/src/typeUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export type Prettify<T> = { [K in keyof T]: T[K] } & {}
2+
13
export type UnionToIntersection<U> = (
24
U extends any ? (k: U) => void : never
35
) extends (k: infer I) => void

0 commit comments

Comments
 (0)