Skip to content

Commit bd99c2d

Browse files
authoredMar 28, 2025··
fix(useOverlay): refine open method type to infer close emit return type (#3716)
1 parent 23bfeb9 commit bd99c2d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎src/runtime/composables/useOverlay.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { Component } from 'vue'
22
import { reactive, markRaw, shallowReactive } from 'vue'
33
import { createSharedComposable } from '@vueuse/core'
4-
import type { ComponentProps } from 'vue-component-type-helpers'
4+
import type { ComponentProps, ComponentEmit } from 'vue-component-type-helpers'
5+
6+
// Extracts the first argument of the close event
7+
type CloseEventArgType<T> = T extends (event: 'close', args_0: infer R) => void ? R : never
58

69
export type OverlayOptions<OverlayAttrs = Record<string, any>> = {
710
defaultOpen?: boolean
@@ -19,7 +22,7 @@ type ManagedOverlayOptionsPrivate<T extends Component> = {
1922
export type Overlay = OverlayOptions<Component> & ManagedOverlayOptionsPrivate<Component>
2023

2124
interface OverlayInstance<T> {
22-
open: (props?: ComponentProps<T>) => Promise<any>
25+
open: (props?: ComponentProps<T>) => Promise<CloseEventArgType<ComponentEmit<T>>>
2326
close: (value?: any) => void
2427
patch: (props: Partial<ComponentProps<T>>) => void
2528
}

0 commit comments

Comments
 (0)
Please sign in to comment.