From 5d549d230d06f8d367613f139a69425701b3e9e4 Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 9 Jan 2025 16:02:10 +0800 Subject: [PATCH] fix(types): EmitsOptions support named tuple syntax --- .../dts-test/defineComponent.test-d.tsx | 14 ++++++++++++++ packages/runtime-core/src/componentEmits.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages-private/dts-test/defineComponent.test-d.tsx b/packages-private/dts-test/defineComponent.test-d.tsx index fda3ca4856c..3ff27f2fea6 100644 --- a/packages-private/dts-test/defineComponent.test-d.tsx +++ b/packages-private/dts-test/defineComponent.test-d.tsx @@ -1368,6 +1368,20 @@ describe('function syntax w/ emits', () => { }, }, ) + + defineComponent< + {}, + { + update: [value: string] // named tuple syntax + } + >((props, ctx) => { + ctx.emit('update', '123') + // @ts-expect-error + ctx.emit('update', 123) + // @ts-expect-error + ctx.emit('non-exist') + return () => {} + }) }) describe('function syntax w/ runtime props', () => { diff --git a/packages/runtime-core/src/componentEmits.ts b/packages/runtime-core/src/componentEmits.ts index db52bc88c33..86230f874b4 100644 --- a/packages/runtime-core/src/componentEmits.ts +++ b/packages/runtime-core/src/componentEmits.ts @@ -35,7 +35,7 @@ import type { ComponentPublicInstance } from './componentPublicInstance' export type ObjectEmitsOptions = Record< string, - ((...args: any[]) => any) | null + ((...args: any[]) => any) | null | any[] > export type EmitsOptions = ObjectEmitsOptions | string[]