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
This utility function returns a Promise containing the first of a list of possible events - whatever the event target emits first. This is useful to avoid polling, to see if a media (or script other other types of) element successfully loads, so for example:
(async()=>{constmedia=document.querySelector("video#my-video");media.load();constevent=awaitfirstEvent(media,["loadedmetadata","abort","error"]);// if (event.type === "error") { ... } etc.})();
Who does this impact? Who is this for?
Anyone working with DOM events.
Describe alternatives you've considered (optional)
The example above is my workaround.
I understand if this is more DOM specific than typing-specific, and therefore might be out of scope for this library - I looked around for other type-only libraries, perhaps with a DOM focus, but didn't find any. I don't know where else to look though. Personally, this library is my go-to for all things types. (and if there was an easier/simpler way to derive the DOM event types using some of the utility-types in this library, that might alleviate some pain as well...)
Is your feature request related to a real problem or use-case?
Yes, anything involving custom functions calling e.g.
addEventListener
on DOM elements.Describe a solution including usage in code example
I found my solution here - and here's a real world example:
This utility function returns a
Promise
containing the first of a list of possible events - whatever the event target emits first. This is useful to avoid polling, to see if a media (or script other other types of) element successfully loads, so for example:Who does this impact? Who is this for?
Anyone working with DOM events.
Describe alternatives you've considered (optional)
The example above is my workaround.
I understand if this is more DOM specific than typing-specific, and therefore might be out of scope for this library - I looked around for other type-only libraries, perhaps with a DOM focus, but didn't find any. I don't know where else to look though. Personally, this library is my go-to for all things types. (and if there was an easier/simpler way to derive the DOM event types using some of the utility-types in this library, that might alleviate some pain as well...)
Additional context (optional)
Open feature request in
microsoft/Typescript
repo.The text was updated successfully, but these errors were encountered: