Closed
Description
Bug Report
π Search Terms
π Version & Regression Information
- This is something that I expected to work after 4.3's Contextual Narrowing for Generics
β― 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
.