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 } 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 = { type HTMLElementEventHandler = {
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: ( [K in keyof HTMLElementEventMap as `on${Capitalize<K>}${EventModifiers}`]?: (
ev: HTMLElementEventMap[K], ev: HTMLElementEventMap[K],
) => any ) => any
} }

View File

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