Skip to content

Add typed overloads for Performance.getEntriesByType/getEntriesByName - #2572

Open
Ankith Burki (Ankith-B) wants to merge 1 commit into
microsoft:mainfrom
Ankith-B:performance-entry-overloads
Open

Ankith Burki (Ankith-B) wants to merge 1 commit into
microsoft:mainfrom
Ankith-B:performance-entry-overloads

Conversation

@Ankith-B

Copy link
Copy Markdown

Fixes microsoft/TypeScript#33866

performance.getEntriesByType() and getEntriesByName(name, type) always return PerformanceEntryList, so callers have to cast to get entry-specific properties.

This adds overloads via additionalSignatures in overridingTypes.jsonc (the same mechanism getContext("2d") uses):

  • getEntriesByType("mark" | "measure" | "resource") → PerformanceMark[] / PerformanceMeasure[] / PerformanceResourceTiming[]
  • the matching getEntriesByName(name, type) overloads
  • on both Performance and PerformanceObserverEntryList

Other strings still return PerformanceEntryList. These three entry types exist in every environment that exposes Performance, so the worker libs get the same overloads. DOM-only entry types such as "navigation", "paint" and "largest-contentful-paint" are left for a follow-up, since adding them naively would make the worker libs reference missing types. Happy to add them if there's a preferred way to make overloads DOM-only.

Testing: npm test passes. I also type-checked usage against the generated dom and webworker libs: the new overloads return the specific types, non-literal strings and "navigation" still return PerformanceEntryList, and assigning resource entries to PerformanceMark[] correctly errors.

getEntriesByType("mark" | "measure" | "resource") and the matching
getEntriesByName(name, type) overloads now return PerformanceMark[],
PerformanceMeasure[] and PerformanceResourceTiming[] instead of the generic
PerformanceEntryList, on both Performance and PerformanceObserverEntryList.
These entry types exist in every environment that exposes Performance, so
the worker libraries get the same overloads. Other entry types keep the
existing PerformanceEntryList signature.

Fixes microsoft/TypeScript#33866

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HePuF24BxGCMzABHKRirN8
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by Kagami Sascha Rosylight (@saschanaz) - if they write a comment saying "LGTM" then it will be merged.

@Ankith-B

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add types for window.performance.getEntriesByType

1 participant