pull/7224/head
Ivan Hofer 4 years ago
parent f50219a55e
commit ba35faea50

@ -64,10 +64,10 @@ type ExtractObjectValues<Object extends Record<any, any>> = Object[keyof Object]
type ConstructDispatchFunction<EventMap extends Record<string, any>, EventKey extends keyof EventMap> = type ConstructDispatchFunction<EventMap extends Record<string, any>, EventKey extends keyof EventMap> =
EventMap[EventKey] extends never | null EventMap[EventKey] extends never | null
? (type: EventKey) => void ? (type: EventKey) => boolean
: null extends EventMap[EventKey] : null extends EventMap[EventKey]
? (type: EventKey, detail?: EventMap[EventKey]) => void ? (type: EventKey, detail?: EventMap[EventKey], options?: DispatchOptions) => boolean
: (type: EventKey, detail: EventMap[EventKey]) => void : (type: EventKey, detail: EventMap[EventKey], options?: DispatchOptions) => boolean
type CreateDispatchFunctionMap<EventMap> = { type CreateDispatchFunctionMap<EventMap> = {
[Key in keyof EventMap]: ConstructDispatchFunction<EventMap, Key> [Key in keyof EventMap]: ConstructDispatchFunction<EventMap, Key>
@ -91,12 +91,10 @@ export interface DispatchOptions {
* *
* https://svelte.dev/docs#run-time-svelte-createeventdispatcher * https://svelte.dev/docs#run-time-svelte-createeventdispatcher
*/ */
export function createEventDispatcher< export function createEventDispatcher<EventMap extends Record<string, any> = any>(): EventDispatcher<EventMap> {
EventMap extends Record<string, any> = any
>(): EventDispatcher<EventMap> {
const component = get_current_component(); const component = get_current_component();
return (type: string, detail?: any, { cancelable = false } = {}): boolean => { return ((type: string, detail?: any, { cancelable = false } = {}): boolean => {
const callbacks = component.$$.callbacks[type]; const callbacks = component.$$.callbacks[type];
if (callbacks) { if (callbacks) {
@ -110,7 +108,7 @@ export function createEventDispatcher<
} }
return true; return true;
}; }) as EventDispatcher<EventMap>;
} }
/** /**

Loading…
Cancel
Save