diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts index 7fe8c0c57e..aad6574384 100644 --- a/src/runtime/internal/lifecycle.ts +++ b/src/runtime/internal/lifecycle.ts @@ -64,7 +64,7 @@ type ExtractObjectValues> = Object[keyof Object] type ConstructDispatchFunction, EventKey extends keyof EventMap> = EventMap[EventKey] extends never | null - ? (type: EventKey) => boolean + ? (type: EventKey, detail?: null, options?: DispatchOptions) => boolean : null extends EventMap[EventKey] ? (type: EventKey, detail?: EventMap[EventKey], options?: DispatchOptions) => boolean : (type: EventKey, detail: EventMap[EventKey], options?: DispatchOptions) => boolean @@ -111,6 +111,16 @@ export function createEventDispatcher = any }) as EventDispatcher; } +// no type restrictions +const dispatch1 = createEventDispatcher() +dispatch1('click') +dispatch1('something') +dispatch1('something', true) + +const dispatch2 = createEventDispatcher<{ click: never }>() +dispatch2('click') +dispatch2('click', true) + /** * Associates an arbitrary `context` object with the current component and the specified `key` * and returns that object. The context is then available to children of the component @@ -153,7 +163,7 @@ export function getAllContexts = Map>(): T { * https://svelte.dev/docs#run-time-svelte-hascontext */ export function hasContext(key): boolean { - return get_current_component().$$.context.has(key); + return get_current_component().$$.context.has(key); } // TODO figure out if we still want to support