Microsoft/TypeScript

Add types for window.performance.getEntriesByType

Open

#33.866 aperta il 8 ott 2019

Vedi su GitHub
 (9 commenti) (15 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
BugDomain: lib.d.tsHelp Wanted

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

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):

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Guida contributor