21 lines
681 B
TypeScript
21 lines
681 B
TypeScript
import type { WindowFormEventMap } from '@/core/window/ui/WindowFormElement.ts'
|
|
|
|
export function addWindowFormEventListener<K extends keyof WindowFormEventMap>(
|
|
el: HTMLElement,
|
|
type: K,
|
|
listener: (ev: WindowFormEventMap[K]) => any,
|
|
options?: boolean | AddEventListenerOptions
|
|
) {
|
|
// 强制类型转换,保证 TS 不报错
|
|
el.addEventListener(type, listener as EventListener, options);
|
|
}
|
|
|
|
export function removeWindowFormEventListener<K extends keyof WindowFormEventMap>(
|
|
el: HTMLElement,
|
|
type: K,
|
|
listener: (ev: WindowFormEventMap[K]) => any,
|
|
options?: boolean | EventListenerOptions
|
|
) {
|
|
el.removeEventListener(type, listener as EventListener, options);
|
|
}
|