Skip to content

Spreading Parameters of ternary function type does not recognize parameter type #40478

@alanthai

Description

@alanthai

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

Actual behavior:
Screen Shot 2020-09-10 at 1 50 49 PM

Playground Link: https://www.typescriptlang.org/play?#code/C4TwDgpgBAogbhAdsAwgQwDYYEZoMYDWAPACpQQAewSAJgM6wLIngQB8UAvFGZdYvSgByAGYRgeABZCAUFCgB+KAAoAtuLQAuKAG8ArgCcM2usAMBLRAHMA3FBqG0wcwHtE2xHtXYIBgL4AlFwccC7mNHJQHhAIBjYyMqCQjEjALMncouJSQvEyeG6mUBjmpki+DNyIEADuUACyaGBEphbWADQpyOhYuIREaIggbADaALpsygF5BYhFVuIAMqX8FVwqManpENrwW6xBnBwlZdUGdAB0C8DKm8wHUAA+j1DjeZRgLgbAUCJ6iHhnG57KUwE4pKRyFRaAw9vdIJNInc0qxtCR2pE0AYrHRtAAFLFodTUc5EOGoTA4fDEEhsNgYoI6SLXZanCq3JgoyABC4iL4wfCSZTKE6rAyHY4rcoGZQXOVYnEBaYyPwyIA

Related Issues: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions