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 摘要。