Repository navigation
Add typed overloads for Performance.getEntriesByType/getEntriesByName - #2572
Open
Ankith Burki (Ankith-B) wants to merge 1 commit into
Open
Ankith Burki (Ankith-B) wants to merge 1 commit into
Ankith Burki (Ankith-B) wants to merge 1 commit into
Conversation
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
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. |
Author
|
@microsoft-github-policy-service agree |
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes microsoft/TypeScript#33866
performance.getEntriesByType()andgetEntriesByName(name, type)always returnPerformanceEntryList, so callers have to cast to get entry-specific properties.This adds overloads via
additionalSignaturesinoverridingTypes.jsonc(the same mechanismgetContext("2d")uses):getEntriesByType("mark" | "measure" | "resource")→PerformanceMark[]/PerformanceMeasure[]/PerformanceResourceTiming[]getEntriesByName(name, type)overloadsPerformanceandPerformanceObserverEntryListOther strings still return
PerformanceEntryList. These three entry types exist in every environment that exposesPerformance, 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 testpasses. I also type-checked usage against the generateddomandwebworkerlibs: the new overloads return the specific types, non-literal strings and"navigation"still returnPerformanceEntryList, and assigning resource entries toPerformanceMark[]correctly errors.