microsoft / microsoft/TypeScript
TS 5.4.5: Return type for performance.getEntriesByType is inaccurate
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
⚙ Compilation target
ESNexr
⚙ Library
lib.dom.d.ts
Missing / Incorrect Definition
The return type for getEntriesByType is a union of many different object types. A list can be seen in the spec, or at https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry ("The PerformanceEntry instances will always be one of the following subclasses:: [List of possibel sub-classes]")
The return type can - and I think should - be hard-coded for the respective string parameter to getEntriesByType, since there is a limited short list of possible string constants, and each corresponds exactly to one possible return type. Maybe an overloaded definition for this function?
Right now the return type is set to PerformanceEntryList, which is PerformanceEntry[], and that type is an interface with only the minimal number of entries.
The effect is that when I use, for example, performance.getEntriesByType('navigation'), I get a TypeScript error trying to access the properties on the PerformanceNavigationTiming array I get from that query.
Sample Code
function pageWasRealoaded(): boolean {
return performance
.getEntriesByType('navigation')
// Error: TS2339: Property type does not exist on type PerformanceEntry
// This is wrong, because this is a PerformanceNavigationTiming object
.some(entry => entry.type === 'reload');
}
Documentation Link
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。