WindowFormElement
This commit is contained in:
20
src/core/window/ui/window-form-helper.ts
Normal file
20
src/core/window/ui/window-form-helper.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user