Skip to content

Commit

Permalink
add typings for createEventDispatcher (sveltejs#5260)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored and taylorzane committed Dec 17, 2020
1 parent e030c11 commit 4dcd950
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/runtime/internal/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export function onDestroy(fn) {
get_current_component().$$.on_destroy.push(fn);
}

export function createEventDispatcher() {
export function createEventDispatcher<
EventMap extends {} = any
>(): <EventKey extends Extract<keyof EventMap, string>>(type: EventKey, detail?: EventMap[EventKey]) => void {
const component = get_current_component();

return (type: string, detail?: any) => {
Expand Down Expand Up @@ -61,4 +63,4 @@ export function bubble(component, event) {
if (callbacks) {
callbacks.slice().forEach(fn => fn(event));
}
}
}

0 comments on commit 4dcd950

Please sign in to comment.