Repository navigation
Add CustomEvent to EventListener - #1535
Chris Ewald (mkcode) wants to merge 2 commits into
Conversation
|
Thanks for the PR! This section of the codebase is owned by Kagami Sascha Rosylight (@saschanaz) - if they write a comment saying "LGTM" then it will be merged. |
|
Kagami Sascha Rosylight (@saschanaz) - Following up on your comment: microsoft/TypeScript#28357 (comment) I believe that extending the EventMap interfaces would not solve the issue for generic EventTargets. This way does, but may break other things. |
|
You should still be able to add your own addEventListener signature in that case and follow the pattern of the existing types. |
|
Yep. This is much more complicated than the DX that I want of just specifying the parameter type of the callback function: object.addEventListener('my-event', (event: CustomEvent<CustomType>) => { event.detail }))But, I think you are right that what I wrote is actually just a bad TypeScript pattern. The type definition belongs in the object definition using the methods you described, not in callback handlers. Thank you. I appreciate your time and detailed response! |
Type definition for EventListener and EventListenerObject is overly narrow and does not allow for CustomEvent.
Submitting this PR on behalf of issue: microsoft/TypeScript#28357
MDN and WhatWG seem to specify that this is allowed: