mirror of https://github.com/vuejs/core.git
feat(dx): improve readability of displayed types for props
This commit is contained in:
parent
58e5c51149
commit
4c9bfd2b99
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue