From 9eca65ee9871d1ac878755afa9a3eb1b02030350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?= <85992002+KazariEX@users.noreply.github.com> Date: Fri, 20 Sep 2024 20:36:57 +0800 Subject: [PATCH] fix(types): correct type inference of all-optional props (#11644) fix #11733 fix vuejs/language-tools#4704 --- packages/runtime-core/src/apiDefineComponent.ts | 12 +++++++----- packages/runtime-core/src/componentProps.ts | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/runtime-core/src/apiDefineComponent.ts b/packages/runtime-core/src/apiDefineComponent.ts index 138f185fca2..3748fc81c63 100644 --- a/packages/runtime-core/src/apiDefineComponent.ts +++ b/packages/runtime-core/src/apiDefineComponent.ts @@ -209,11 +209,13 @@ export function defineComponent< ? TypeEmitsToOptions : RuntimeEmitsOptions, InferredProps = unknown extends TypeProps - ? string extends RuntimePropsKeys - ? ComponentObjectPropsOptions extends RuntimePropsOptions - ? {} - : ExtractPropTypes - : { [key in RuntimePropsKeys]?: any } + ? keyof TypeProps extends never + ? string extends RuntimePropsKeys + ? ComponentObjectPropsOptions extends RuntimePropsOptions + ? {} + : ExtractPropTypes + : { [key in RuntimePropsKeys]?: any } + : TypeProps : TypeProps, TypeRefs extends Record = {}, TypeEl extends Element = any, diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index c864ba15535..e07fb476788 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -125,7 +125,9 @@ type InferPropType = [T] extends [null] : InferPropType : [T] extends [Prop] ? unknown extends V - ? IfAny + ? keyof V extends never + ? IfAny + : V : V : T