diff --git a/packages/runtime-core/src/apiDefineComponent.ts b/packages/runtime-core/src/apiDefineComponent.ts index 3748fc81c63..d5e2feb5e6d 100644 --- a/packages/runtime-core/src/apiDefineComponent.ts +++ b/packages/runtime-core/src/apiDefineComponent.ts @@ -27,7 +27,7 @@ import type { EmitsToProps, TypeEmitsToOptions, } from './componentEmits' -import { extend, isFunction } from '@vue/shared' +import { type IsKeyValues, extend, isFunction } from '@vue/shared' import type { VNodeProps } from './vnode' import type { ComponentPublicInstanceConstructor, @@ -208,15 +208,13 @@ export function defineComponent< ResolvedEmits extends EmitsOptions = {} extends RuntimeEmitsOptions ? TypeEmitsToOptions : RuntimeEmitsOptions, - InferredProps = unknown extends TypeProps - ? keyof TypeProps extends never - ? string extends RuntimePropsKeys - ? ComponentObjectPropsOptions extends RuntimePropsOptions - ? {} - : ExtractPropTypes - : { [key in RuntimePropsKeys]?: any } - : TypeProps - : TypeProps, + InferredProps = IsKeyValues extends true + ? TypeProps + : string extends RuntimePropsKeys + ? ComponentObjectPropsOptions extends RuntimePropsOptions + ? {} + : ExtractPropTypes + : { [key in RuntimePropsKeys]?: any }, TypeRefs extends Record = {}, TypeEl extends Element = any, >( diff --git a/packages/shared/src/typeUtils.ts b/packages/shared/src/typeUtils.ts index 1fd161ceb05..f5b9e6ec3c8 100644 --- a/packages/shared/src/typeUtils.ts +++ b/packages/shared/src/typeUtils.ts @@ -13,6 +13,12 @@ export type LooseRequired = { [P in keyof (T & Required)]: T[P] } // https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360 export type IfAny = 0 extends 1 & T ? Y : N +export type IsKeyValues = 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) * https://github.com/microsoft/TypeScript/issues/32164#issuecomment-1146737709