CallbackArguments<EventMap, EventName>
Resolves callback argument types for an event.
- When
EventMaphas an index signature (untyped default): returnsunknown[], allowingArgsto be inferred freely from the callback. - WhenEventMaphas explicit keys only (typed map): returnsEventMap[EventName], enforcing the declared argument types and enabling autocomplete.
The typed branch is an indexed access rather than a conditional on EventName, so it stays resolvable when EventName is itself a type parameter: a caller generic over the event name, such as subscribe<Name extends keyof Map>(name: Name, listener: (...payload: Map[Name]) => void), can pass its listener (or its payload) straight through, because Map[Name] relates to Map[Name & keyof Map].
Import:
import type { CallbackArguments } from '@mnaoumov/typescript-lib/async-events';Signature:
export type CallbackArguments<EventMap, EventName extends string>Signature:
type CallbackArguments<EventMap, EventName> = string extends keyof EventMap ? unknown[] : EventMap[EventName & keyof EventMap]Type: string extends keyof EventMap ? unknown[] : EventMap[EventName & keyof EventMap]
Links to this page: