You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we use fromEvent in web we can extract type of event from the map of event names that are present in TypeScript.
It is also often helpful to have currentTarget of that event to have the same type as the target we listen this event on so we do not have to typecast low level EventTarget when we work with it down the RxJS line.
currentTarget type is questionable because it changes. currentTarget only matches the element we listen event on directly in the callback. So this might not be a good idea but it's up for a debate :)
Here's a little proof of concept with events on Element, Window and Document with fallback to current fromEvent behavior where we just have generic:
When we use
fromEvent
in web we can extract type of event from the map of event names that are present in TypeScript.It is also often helpful to have
currentTarget
of that event to have the same type as the target we listen this event on so we do not have to typecast low levelEventTarget
when we work with it down the RxJS line.currentTarget
type is questionable because it changes.currentTarget
only matches the element we listen event on directly in the callback. So this might not be a good idea but it's up for a debate :)Here's a little proof of concept with events on
Element
,Window
andDocument
with fallback to currentfromEvent
behavior where we just have generic:https://stackblitz.com/edit/angular-typed-fromevent-delux
This could be a starting point for discussion/implementation.
The text was updated successfully, but these errors were encountered: