Skip to content

Contextual narrowing not narrowing on generic map. #45234

Description

Bug Report

🔎 Search Terms

🕗 Version & Regression Information

⏯ Playground Link

Playground link with relevant code

💻 Code

declare const eventType: keyof DocumentEventMap;

document.addEventListener(eventType, (event) => {
  event; // Here `event` is `Event | UIEvent | AnimationEvent | MouseEvent | InputEvent | FocusEvent | CompositionEvent | ... 9 more ... | ClipboardEvent
  if (eventType === `click`) {
    event; // Expected: `event` to be type `MouseEvent`. Actual: It's the union from above.
  }
});

🙁 Actual behavior

Second reference of event is type Event | UIEvent | AnimationEvent | MouseEvent | InputEvent | FocusEvent | CompositionEvent | ... 9 more ... | ClipboardEvent.

🙂 Expected behavior

Second reference of event to be of type MouseEvent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions