fix: event types

This commit is contained in:
teleskop150750 2025-01-09 08:36:51 +03:00
parent 22dcbf3e20
commit 68c4eedc0f
2 changed files with 17 additions and 7 deletions

View File

@ -75,8 +75,14 @@ interface Constructor<P = any> {
new (...args: any[]): { $props: P }
}
type CombineModifiers<T extends string, U extends string = T> = T extends any
? T | `${T}${CombineModifiers<Exclude<U, T>>}`
: never
type EventModifiers = CombineModifiers<'Capture' | 'Once' | 'Passive'> | ''
type HTMLElementEventHandler = {
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}${EventModifiers}`]?: (
ev: HTMLElementEventMap[K],
) => any
}

View File

@ -252,7 +252,7 @@ export type StyleValue =
| CSSProperties
| Array<StyleValue>
export interface HTMLAttributes extends AriaAttributes, EventHandlers<Events> {
export interface HTMLAttributes extends AriaAttributes, EventHandlers {
innerHTML?: string
class?: any
@ -808,7 +808,7 @@ export interface WebViewHTMLAttributes extends HTMLAttributes {
webpreferences?: string
}
export interface SVGAttributes extends AriaAttributes, EventHandlers<Events> {
export interface SVGAttributes extends AriaAttributes, EventHandlers {
innerHTML?: string
/**
@ -1384,10 +1384,14 @@ export interface Events {
onTransitionstart: TransitionEvent
}
type EventHandlers<E> = {
[K in keyof E]?: E[K] extends (...args: any) => any
? E[K]
: (payload: E[K]) => void
type CombineModifiers<T extends string, U extends string = T> = T extends any
? T | `${T}${CombineModifiers<Exclude<U, T>>}`
: never
type EventModifiers = CombineModifiers<'Capture' | 'Once' | 'Passive'> | ''
type EventHandlers = {
[K in keyof Events as `${K}${EventModifiers}`]?: (payload: Events[K]) => void
}
import type { VNodeRef } from '@vue/runtime-core'