From 5dbd6b36a0666fc6c993115ee5281ef253ba8a68 Mon Sep 17 00:00:00 2001 From: wonderful-panda Date: Tue, 22 Sep 2020 23:05:37 +0900 Subject: [PATCH] fix(types): fix using tuple type as EmitsOptions (#2160) fix #2159 --- packages/runtime-core/src/componentEmits.ts | 4 ++-- test-dts/functionalComponent.test-d.tsx | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/componentEmits.ts b/packages/runtime-core/src/componentEmits.ts index 6418f8c7d..daf82b71e 100644 --- a/packages/runtime-core/src/componentEmits.ts +++ b/packages/runtime-core/src/componentEmits.ts @@ -28,8 +28,8 @@ export type EmitsOptions = ObjectEmitsOptions | string[] export type EmitFn< Options = ObjectEmitsOptions, Event extends keyof Options = keyof Options -> = Options extends any[] - ? (event: Options[0], ...args: any[]) => void +> = Options extends Array + ? (event: V, ...args: any[]) => void : {} extends Options // if the emit is empty object (usually the default value for emit) should be converted to function ? (event: string, ...args: any[]) => void : UnionToIntersection< diff --git a/test-dts/functionalComponent.test-d.tsx b/test-dts/functionalComponent.test-d.tsx index c53c4287a..4fe4db645 100644 --- a/test-dts/functionalComponent.test-d.tsx +++ b/test-dts/functionalComponent.test-d.tsx @@ -63,3 +63,12 @@ const Baz: FunctionalComponent<{}, string[]> = (props, { emit }) => { } expectType(Baz) + +const Qux: FunctionalComponent<{}, ['foo', 'bar']> = (props, { emit }) => { + emit('foo') + emit('foo', 1, 2) + emit('bar') + emit('bar', 1, 2) +} + +expectType(Qux)