From 1022eabaa1aaf8436876f5ec5573cb1e4b3959a6 Mon Sep 17 00:00:00 2001 From: edison Date: Fri, 15 Nov 2024 10:46:59 +0800 Subject: [PATCH] fix(types): defineEmits w/ interface declaration (#12343) close #8457 --- packages-private/dts-test/setupHelpers.test-d.ts | 8 ++++++++ packages/runtime-core/src/apiSetupHelpers.ts | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages-private/dts-test/setupHelpers.test-d.ts b/packages-private/dts-test/setupHelpers.test-d.ts index 7b5d6f147f0..656f1da79f2 100644 --- a/packages-private/dts-test/setupHelpers.test-d.ts +++ b/packages-private/dts-test/setupHelpers.test-d.ts @@ -306,6 +306,14 @@ describe('defineEmits w/ type declaration', () => { emit2('baz') }) +describe('defineEmits w/ interface declaration', () => { + interface Emits { + foo: [value: string] + } + const emit = defineEmits() + emit('foo', 'hi') +}) + describe('defineEmits w/ alt type declaration', () => { const emit = defineEmits<{ foo: [id: string] diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index 54712c6807a..2ddaeb509ad 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -149,9 +149,7 @@ export function defineEmits() { return null as any } -export type ComponentTypeEmits = - | ((...args: any[]) => any) - | Record +export type ComponentTypeEmits = ((...args: any[]) => any) | Record type RecordToUnion> = T[keyof T]