google / google/closure-compiler
Element onclick handler and others expect Event or null
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
The DOM Level 1 event handlers like `onclick` and `onkeyup`, as currently written, allow for a null Event object [in the externs](https://github.com/google/closure-compiler/blob/master/externs/browser/w3c_dom1.js#L683). This means that in order to compile without that warning, you have to make your event function accept null. And when doing that, it then has to cast to not null in order to actually use the Event object safely. As far as I know these handlers are always passed an event object, unless you call them yourself. Is there a reason why null is allowed there or is that just an oversight? If the latter, I think they should all be changed to `!Event`.
EDIT: Is it perhaps for old IE support where the event object had to be retrieved with `window.event`? That would make some sense, but would be wrong for newer browsers, right?
Contributor guide
Assessment
This issue has not been assessed yet.