Skip to content

Contextual narrowing not narrowing on generic map.Β #45234

Closed
@whitneyit

Description

@whitneyit

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