Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Oct 15, 2018
1 parent 8c20fa7 commit 27f1fae
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/bindEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
type UnbindFn = () => void
export type BindEventTypes = string | string[]
export type BindEventListener = EventListenerOrEventListenerObject
export type BindEventOptions = boolean | AddEventListenerOptions
export type UnbindEventListener = () => void

/**
* 将指定类型的事件绑定在指定的目标上并返回解绑函数。
Expand All @@ -10,10 +13,10 @@ type UnbindFn = () => void
*/
export default function bindEvent(
target: EventTarget,
types: string | string[],
types: BindEventTypes,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
): UnbindFn {
options?: BindEventOptions
): UnbindEventListener {
const disposes: Array<() => void> = [];
(Array.isArray(types) ? types : types.split(/\s+/)).forEach(eventType => {
target.addEventListener(eventType, listener, options)
Expand Down

0 comments on commit 27f1fae

Please sign in to comment.