forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add overloads to correct place, put it into dts for now because of mi…
- Loading branch information
1 parent
14e5e3c
commit c3d4590
Showing
6 changed files
with
104 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Once https://github.com/microsoft/TypeScript/issues/59980 is fixed we can put these overloads into the JSDoc comments of the `on` function | ||
|
||
/** | ||
* Attaches an event handler to the window and returns a function that removes the handler. Using this | ||
* rather than `addEventListener` will preserve the correct order relative to handlers added declaratively | ||
* (with attributes like `onclick`), which use event delegation for performance reasons | ||
*/ | ||
export function on<Type extends keyof WindowEventMap>( | ||
window: Window, | ||
type: Type, | ||
handler: (this: Window, event: WindowEventMap[Type]) => any, | ||
options?: AddEventListenerOptions | undefined | ||
): () => void; | ||
/** | ||
* Attaches an event handler to the document and returns a function that removes the handler. Using this | ||
* rather than `addEventListener` will preserve the correct order relative to handlers added declaratively | ||
* (with attributes like `onclick`), which use event delegation for performance reasons | ||
*/ | ||
export function on<Type extends keyof DocumentEventMap>( | ||
document: Document, | ||
type: Type, | ||
handler: (this: Document, event: DocumentEventMap[Type]) => any, | ||
options?: AddEventListenerOptions | undefined | ||
): () => void; | ||
/** | ||
* Attaches an event handler to an element and returns a function that removes the handler. Using this | ||
* rather than `addEventListener` will preserve the correct order relative to handlers added declaratively | ||
* (with attributes like `onclick`), which use event delegation for performance reasons | ||
*/ | ||
export function on<Element extends HTMLElement, Type extends keyof HTMLElementEventMap>( | ||
element: Element, | ||
type: Type, | ||
handler: (this: Element, event: HTMLElementEventMap[Type]) => any, | ||
options?: AddEventListenerOptions | undefined | ||
): () => void; | ||
/** | ||
* Attaches an event handler to an element and returns a function that removes the handler. Using this | ||
* rather than `addEventListener` will preserve the correct order relative to handlers added declaratively | ||
* (with attributes like `onclick`), which use event delegation for performance reasons | ||
*/ | ||
export function on<Element extends MediaQueryList, Type extends keyof MediaQueryListEventMap>( | ||
element: Element, | ||
type: Type, | ||
handler: (this: Element, event: MediaQueryListEventMap[Type]) => any, | ||
options?: AddEventListenerOptions | undefined | ||
): () => void; | ||
/** | ||
* Attaches an event handler to an element and returns a function that removes the handler. Using this | ||
* rather than `addEventListener` will preserve the correct order relative to handlers added declaratively | ||
* (with attributes like `onclick`), which use event delegation for performance reasons | ||
*/ | ||
export function on( | ||
element: EventTarget, | ||
type: string, | ||
handler: EventListener, | ||
options?: AddEventListenerOptions | undefined | ||
): () => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters