fix(useOverlay): support infering close argument from complex emits (#4414)

Co-authored-by: Eugen Istoc <eugenistoc@gmail.com>
This commit is contained in:
Teages
2025-07-03 16:45:19 +08:00
committed by GitHub
parent 8922c7388e
commit d7aefa53b2

View File

@@ -3,9 +3,34 @@ import { reactive, markRaw, shallowReactive } from 'vue'
import { createSharedComposable } from '@vueuse/core'
import type { ComponentProps, ComponentEmit } from 'vue-component-type-helpers'
// Extracts the first argument of the close event
type CloseEventArgType<T> = T extends (event: 'close', args_0: infer R) => void ? R : never
/**
* This is a workaround for a design limitation in TypeScript.
*
* Conditional types only match the last function overload, not a union of all possible
* parameter types. This workaround forces TypeScript to properly extract the 'close'
* event argument type from component emits with multiple event signatures.
*
* @see https://github.com/microsoft/TypeScript/issues/32164
*/
type CloseEventArgType<T> = T extends {
(event: 'close', arg_0: infer Arg, ...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
(...args: any[]): void
} ? Arg : never
export type OverlayOptions<OverlayAttrs = Record<string, any>> = {
defaultOpen?: boolean
props?: OverlayAttrs