Skip to content

Commit

Permalink
fix(types): correct type inference of union event names (#12022)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Sep 26, 2024
1 parent 6001e5c commit 4da6881
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/runtime-core/src/componentEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,23 @@ export type TypeEmitsToOptions<T extends ComponentTypeEmits> = {
: {})

type ParametersToFns<T extends any[]> = {
[K in T[0]]: K extends `${infer C}`
? (...args: T extends [C, ...infer Args] ? Args : never) => any
[K in T[0]]: IsStringLiteral<K> extends true
? (
...args: T extends [e: infer E, ...args: infer P]
? K extends E
? P
: never
: never
) => any
: never
}

type IsStringLiteral<T> = T extends string
? string extends T
? false
: true
: false

export type ShortEmitsToObject<E> =
E extends Record<string, any[]>
? {
Expand Down

0 comments on commit 4da6881

Please sign in to comment.