microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.21k stars 12.51k forks source link

Add types for window.performance.getEntriesByType #33866

Open third774 opened 5 years ago

third774 commented 5 years ago

Search Terms

getEntriesByType PerformanceMark PerformanceMeasure PerformanceResourceTiming

Suggestion

Add types for the getEntriesByType API

I found this old issue (Jul 5, 2018) and saw that experimental API's are not included in lib.dom.d.ts. The following API's don't appear to have experimental warnings on them on the MDN docs. Hopefully this means these are no longer experimental and types can be added now?

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMark https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMeasure https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming

Use Cases

Getting specific strongly typed information for the entries when accessed via this API.

Examples

// resources would be of type PerformanceResourceTiming[]
const resources = window.navigation.getEntriesByType("resource");

// resources would be of type PerformanceMeasure[]
const measures = window.navigation.getEntriesByType("measure");

// marks would be of type PerformanceMark[]
const marks = window.navigation.getEntriesByType("mark");

// paints would still be of type PerformanceEntryList
const paints = window.navigation.getEntriesByType("paint");

Checklist

My suggestion meets these guidelines (not sure about the first one):

third774 commented 5 years ago

Doh! Tried to open a PR for this, but looks like the work is over in https://github.com/Microsoft/TSJS-lib-generator. Should I move this issue to that repo?

TaylorPzreal commented 4 years ago

Waiting the feature.

DerGernTod commented 2 years ago

any updates on this?

HolgerJeromin commented 2 years ago

This is fixed since a few versions. Probably 4.4 or even earlier. https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1094#issuecomment-894845936

billyvg commented 2 years ago

@HolgerJeromin That is a different issue that doesn't address the return type of getEntriesByType(), see https://www.typescriptlang.org/play?ssl=14&ssc=1&pln=14&pc=61#code/PTAEAUFMCcDMHtoFsCGA7AxpAcigbgJYDmKALgfGgCoFIFpEDaAugFAaUDOpoa+xZCmgCiaUtAKROoALygA7vQAm8eQDoADjATJ0WNUUilR4yZwBCATyqWtACgDkfQiXKUHASgDcrViAjaiKiYkABKUvAArtBYNHQMLOxcPNAR0VjScopoKupacEF6kAZGJhJSVjb2AESpnFExkNXevv5QBbohALKQKJzRkIkcaNygSL39dbIKyqqagZ36hsZi5RbWtpB21eN9A80+fmDtOsFYXSjQANZDyWOXV5kzOXP5p0UlK6YVGzWo1wdWscFmdIOAUPRSHF6EQkiMeBoIWIntlcvMOqDPmUzJVNttEZCDkA

HolgerJeromin commented 2 years ago

Ok, missed that detail. Current state models spec: https://w3c.github.io/performance-timeline/#extensions-to-the-performance-interface

But yes could be more clear by adding overridingTypes: https://github.com/microsoft/TypeScript-DOM-lib-generator#when-the-type-exists-but-is-wrong

BTW, added type debug information to your playground link.

schickling commented 1 year ago

Is someone aware of any available NPM package that provides the missing types as a workaround for now?