Skip to content

Commit

Permalink
fix(types): correctly infer TypeEmits with both tuple and function …
Browse files Browse the repository at this point in the history
…syntax (#11840)

close #11836
  • Loading branch information
KazariEX authored Sep 6, 2024
1 parent 632e163 commit dad6738
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/runtime-core/src/componentEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ export type EmitsToProps<T extends EmitsOptions | ComponentTypeEmits> =
}
: {}

export type TypeEmitsToOptions<T extends ComponentTypeEmits> =
T extends Record<string, any[]>
? {
[K in keyof T]: T[K] extends [...args: infer Args]
? (...args: Args) => any
: () => any
}
: T extends (...args: any[]) => any
? ParametersToFns<OverloadParameters<T>>
: {}
export type TypeEmitsToOptions<T extends ComponentTypeEmits> = {
[K in keyof T & string]: T[K] extends [...args: infer Args]
? (...args: Args) => any
: () => any
} & (T extends (...args: any[]) => any
? ParametersToFns<OverloadParameters<T>>
: {})

type ParametersToFns<T extends any[]> = {
[K in T[0]]: K extends `${infer C}`
Expand Down

0 comments on commit dad6738

Please sign in to comment.