fix(types): correctly infer `TypeProps` when it is `any` (#12073)
close #12058
This commit is contained in:
parent
577edca8e7
commit
57315ab968
|
@ -27,7 +27,7 @@ import type {
|
||||||
EmitsToProps,
|
EmitsToProps,
|
||||||
TypeEmitsToOptions,
|
TypeEmitsToOptions,
|
||||||
} from './componentEmits'
|
} from './componentEmits'
|
||||||
import { extend, isFunction } from '@vue/shared'
|
import { type IsKeyValues, extend, isFunction } from '@vue/shared'
|
||||||
import type { VNodeProps } from './vnode'
|
import type { VNodeProps } from './vnode'
|
||||||
import type {
|
import type {
|
||||||
ComponentPublicInstanceConstructor,
|
ComponentPublicInstanceConstructor,
|
||||||
|
@ -208,15 +208,13 @@ export function defineComponent<
|
||||||
ResolvedEmits extends EmitsOptions = {} extends RuntimeEmitsOptions
|
ResolvedEmits extends EmitsOptions = {} extends RuntimeEmitsOptions
|
||||||
? TypeEmitsToOptions<TypeEmits>
|
? TypeEmitsToOptions<TypeEmits>
|
||||||
: RuntimeEmitsOptions,
|
: RuntimeEmitsOptions,
|
||||||
InferredProps = unknown extends TypeProps
|
InferredProps = IsKeyValues<TypeProps> extends true
|
||||||
? keyof TypeProps extends never
|
? TypeProps
|
||||||
? string extends RuntimePropsKeys
|
: string extends RuntimePropsKeys
|
||||||
? ComponentObjectPropsOptions extends RuntimePropsOptions
|
? ComponentObjectPropsOptions extends RuntimePropsOptions
|
||||||
? {}
|
? {}
|
||||||
: ExtractPropTypes<RuntimePropsOptions>
|
: ExtractPropTypes<RuntimePropsOptions>
|
||||||
: { [key in RuntimePropsKeys]?: any }
|
: { [key in RuntimePropsKeys]?: any },
|
||||||
: TypeProps
|
|
||||||
: TypeProps,
|
|
||||||
TypeRefs extends Record<string, unknown> = {},
|
TypeRefs extends Record<string, unknown> = {},
|
||||||
TypeEl extends Element = any,
|
TypeEl extends Element = any,
|
||||||
>(
|
>(
|
||||||
|
|
|
@ -13,6 +13,12 @@ export type LooseRequired<T> = { [P in keyof (T & Required<T>)]: T[P] }
|
||||||
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
||||||
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
|
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
|
||||||
|
|
||||||
|
export type IsKeyValues<T, K = string> = IfAny<
|
||||||
|
T,
|
||||||
|
false,
|
||||||
|
T extends object ? (keyof T extends K ? true : false) : false
|
||||||
|
>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for extracting the parameters from a function overload (for typed emits)
|
* Utility for extracting the parameters from a function overload (for typed emits)
|
||||||
* https://github.com/microsoft/TypeScript/issues/32164#issuecomment-1146737709
|
* https://github.com/microsoft/TypeScript/issues/32164#issuecomment-1146737709
|
||||||
|
|
Loading…
Reference in New Issue