Skip to content

Commit d7aefa5

Browse files
Teagesgenu
andauthored
fix(useOverlay): support infering close argument from complex emits (#4414)
Co-authored-by: Eugen Istoc <[email protected]>
1 parent 8922c73 commit d7aefa5

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/runtime/composables/useOverlay.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,34 @@ import { reactive, markRaw, shallowReactive } from 'vue'
33
import { createSharedComposable } from '@vueuse/core'
44
import type { ComponentProps, ComponentEmit } from 'vue-component-type-helpers'
55

6-
// Extracts the first argument of the close event
7-
type CloseEventArgType<T> = T extends (event: 'close', args_0: infer R) => void ? R : never
8-
6+
/**
7+
* This is a workaround for a design limitation in TypeScript.
8+
*
9+
* Conditional types only match the last function overload, not a union of all possible
10+
* parameter types. This workaround forces TypeScript to properly extract the 'close'
11+
* event argument type from component emits with multiple event signatures.
12+
*
13+
* @see https://github.com/microsoft/TypeScript/issues/32164
14+
*/
15+
type CloseEventArgType<T> = T extends {
16+
(event: 'close', arg_0: infer Arg, ...args: any[]): void
17+
(...args: any[]): void
18+
(...args: any[]): void
19+
(...args: any[]): void
20+
(...args: any[]): void
21+
(...args: any[]): void
22+
(...args: any[]): void
23+
(...args: any[]): void
24+
(...args: any[]): void
25+
(...args: any[]): void
26+
(...args: any[]): void
27+
(...args: any[]): void
28+
(...args: any[]): void
29+
(...args: any[]): void
30+
(...args: any[]): void
31+
(...args: any[]): void
32+
(...args: any[]): void
33+
} ? Arg : never
934
export type OverlayOptions<OverlayAttrs = Record<string, any>> = {
1035
defaultOpen?: boolean
1136
props?: OverlayAttrs

0 commit comments

Comments
 (0)