sindresorhus/element-ready

Use types directly from querySelector, without copying them

Offen

#32 geöffnet am 29.12.2020

 (0 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)JavaScript (17 Forks)user submission
enhancementhelp wanted

Repository-Metriken

Stars
 (447 Sterne)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

If the selector is 'a', querySelector‘s return type is be HTMLAnchorElement. To achieve the same in element-ready, we had to manually copy its types and adapt them to elementReady

Ideally, instead, we should try to “inherit” directly from the global querySelector so that, if its types are enhanced (via typed-query-selector or natively), element-ready automatically gets upgraded.

Note: We can't use Parameters<typeof querySelector> and such because it doesn't support overloads nor generics.

This has been unsuccessfully tried in #31. More info about it in that PR. A possible solution might be https://github.com/microsoft/TypeScript/issues/33185#issuecomment-526969274

Contributor Guide