Skip to content

Conversation

@sandersn
Copy link
Member

@sandersn sandersn commented Apr 9, 2019

…MLFrameSetElement"

This reverts commit 1f7b275.

That commit made document.body a union type, which in turns makes methods like addEventListener unions of overloaded signatures, which do not resolve correctly for the following example code, which I believe is very common:

document.body.addEventListener('click', (event) => {
    cx = event.pageX;
    cy = event.pageY;
});

With the union type, event: Event, which does not have pageX or pageY properties. After reverting this commit, event: MouseEvent, which does.

@HolgerJeromin
Copy link
Contributor

Why does a click handler on a HTMLFrameSetElement does not get a MouseEvent?

@sandersn
Copy link
Member Author

It does, and so one on a HTMLBodyElement. But
document.body : HTMLBodyElement | HTMLFrameSetElement,
and (HTMLBodyElement | HTMLFrameSetElement)['addEventListener']
isn't an overloaded signature like HTMLFrameSetElement['addEventListener'] is. It just has one signature with a callback that passes event: Event. So document.body.addEventListener's callback never gets anything but event: Event.

@sandersn sandersn merged commit b6b3cb9 into master Apr 10, 2019
@sandersn sandersn deleted the revert-654 branch April 10, 2019 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants