From 5860cccb206b3b71e1283f064ae0bece5d7b170d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Sat, 9 Dec 2023 08:29:52 +0800 Subject: [PATCH 1/2] types(emits): simplify types --- packages/runtime-core/src/componentEmits.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/runtime-core/src/componentEmits.ts b/packages/runtime-core/src/componentEmits.ts index f3a30f7c953..1bf73d94bcf 100644 --- a/packages/runtime-core/src/componentEmits.ts +++ b/packages/runtime-core/src/componentEmits.ts @@ -38,19 +38,14 @@ export type EmitsOptions = ObjectEmitsOptions | string[] export type EmitsToProps = T extends string[] ? { - [K in string & `on${Capitalize}`]?: (...args: any[]) => any + [K in `on${Capitalize}`]?: (...args: any[]) => any } : T extends ObjectEmitsOptions ? { - [K in string & - `on${Capitalize}`]?: K extends `on${infer C}` - ? T[Uncapitalize] extends null - ? (...args: any[]) => any - : ( - ...args: T[Uncapitalize] extends (...args: infer P) => any - ? P - : never - ) => any + [K in `on${Capitalize}`]?: K extends `on${infer C}` + ? T[Uncapitalize] extends (...args: infer P) => any + ? (...args: P) => any + : (...args: any[]) => any : never } : {} From b133c8c294322e88733c4ef1d4bb092fb9f13f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Mon, 11 Dec 2023 15:23:06 +0800 Subject: [PATCH 2/2] fix(types): fix `EmitsToProps` type error --- packages/runtime-core/src/componentEmits.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/runtime-core/src/componentEmits.ts b/packages/runtime-core/src/componentEmits.ts index 1bf73d94bcf..d56877adb58 100644 --- a/packages/runtime-core/src/componentEmits.ts +++ b/packages/runtime-core/src/componentEmits.ts @@ -43,9 +43,13 @@ export type EmitsToProps = T extends string[] : T extends ObjectEmitsOptions ? { [K in `on${Capitalize}`]?: K extends `on${infer C}` - ? T[Uncapitalize] extends (...args: infer P) => any - ? (...args: P) => any - : (...args: any[]) => any + ? ( + ...args: T[Uncapitalize] extends (...args: infer P) => any + ? P + : T[Uncapitalize] extends null + ? any[] + : never + ) => any : never } : {}