From 482514b8af9411d5c35b65c5f12ec847053c253f Mon Sep 17 00:00:00 2001 From: Pier Fumagalli Date: Tue, 28 Nov 2023 18:49:56 +0100 Subject: [PATCH] fix(runtime-core): extra fixes for when `V` is `unknown` --- packages/dts-test/setupHelpers.test-d.ts | 7 +++---- packages/runtime-core/src/componentProps.ts | 14 ++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/dts-test/setupHelpers.test-d.ts b/packages/dts-test/setupHelpers.test-d.ts index 2404d9bcc89..f09e9029550 100644 --- a/packages/dts-test/setupHelpers.test-d.ts +++ b/packages/dts-test/setupHelpers.test-d.ts @@ -200,12 +200,12 @@ describe('defineProps w/ generics and runtime declarations', () => { foo: { type: Object as PropType, required: false, - default: null, + default: null }, bar: { type: Object as PropType, - required: true, - }, + required: true + } }) expectType(props.foo) expectType(props.bar) @@ -213,7 +213,6 @@ describe('defineProps w/ generics and runtime declarations', () => { test() }) - describe('defineEmits w/ type declaration', () => { const emit = defineEmits<(e: 'change') => void>() emit('change') diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 672843ce198..93a459b09a6 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -125,12 +125,14 @@ type InferPropType = [T] extends [null] : [T] extends [PropOptions] ? unknown extends D ? V - : V | D - : [T] extends [Prop] - ? unknown extends V - ? IfAny - : V - : T + : unknown extends V + ? IfAny + : V + : [T] extends [Prop] + ? unknown extends V + ? IfAny + : V + : T /** * Extract prop types from a runtime props options object.