Add TypeScript declaration for the performance global

未關閉 適合新手
#58,610 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
85/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
react-native, typescript
領域
mobile-dev

研究方向

從 src/types/globals.d.ts 開始,將其中的宣告與 src/private/webapis/performance/Performance.js 以及 Libraries/Core/setUpPerformance.js 中的全域設定進行比較。驗證回報的 tsconfig 和範例 TypeScript 檔案,然後確認全域 performance 和 Performance 型別能夠在沒有 TypeScript 錯誤的情況下公開列出的 API。

由索引模型根據 Issue 內容生成。

描述

Needs: Author Feedback Needs: Repro
Description

Hey! React Native installs a performance global on every app, but its TypeScript types do not declare it.

  • Libraries/Core/setUpPerformance.js installs the global. It uses setUpPerformanceModern() when NativePerformance exists, and a fallback with only performance.now() otherwise.
  • src/private/webapis/performance/Performance.js is the implementation: now, timeOrigin, mark, measure, clearMarks, clearMeasures, getEntries, getEntriesByType, getEntriesByName, memory, eventCounts, rnStartupTiming.
  • src/types/globals.d.ts declares neither performance nor Performance. No other .d.ts in the package does.

This is the same gap as #56325 (TextEncoder / TextDecoder).

Happy to submit a PR if that helps

Steps to reproduce

tsconfig.json

{ "compilerOptions": { "lib": ["es2022"], "types": ["react-native"], "strict": true, "noEmit": true } }

.ts file

const start = performance.now();
const p: Performance = performance;

error

error TS2304: Cannot find name 'performance'.
error TS2304: Cannot find name 'Performance'.
React Native Version

0.85.3

Affected Platforms

Other (please specify)

Output of npx @react-native-community/cli info
this is just adding ts declarations
Stacktrace or Logs
this is just adding ts declarations
MANDATORY Reproducer

this is just adding ts declarations

Screenshots and Videos

No response

主要語言
C++
星號
127k
分支
25.3k
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

react/react-native 的其他 Issue

查看 react/react-native 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。