-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: 4.0.2
Search Terms: spread, parameters, ternary
Code
type EventCallback<T extends EventType> = T extends 'fetch'
? (meta: {url: string; duration: number}) => void
: never;
type EventType = 'fetch';
const listeners = new Map<string, EventCallback<any>[]>();
const getListeners = (eventType: EventType) => listeners.get(eventType) || [];
export function dispatch<T extends EventType>(
eventType: T,
args: Parameters<EventCallback<T>>,
) {
getListeners(eventType).forEach((listener) => listener(...args));
}
Expected behavior:
No error
Related Issues: None
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed