The published types reference src/types/globals.d.ts, whose globals conflict with TypeScript's DOM library under skipLibCheck: false

未关闭
#59,649 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react-native, typescript

调研方向

Start with the types_generated/index.d.ts reference to src/types/globals.d.ts and the mandatory reproducer linked in the issue. Run yarn check:dom there to confirm the declaration conflicts with the DOM library. The issue is resolved when importing View with the stated TypeScript settings produces no errors from React Native's declarations.

由索引模型根据 Issue 内容生成。

描述

Description

types_generated/index.d.ts, the declaration file the package's exports name for react-native, starts with /// <reference path="../src/types/globals.d.ts" />. That file (globals.d.ts) declares its own fetch, Headers, Request, Response, FormData, XMLHttpRequest, URL, URLSearchParams, WebSocket, Blob, File, FileReader, AbortController, AbortSignal and timers as globals, and they differ from the declarations TypeScript's lib.dom.d.ts makes of the same names. So a project that type-checks its dependencies' declarations (skipLibCheck: false) and includes the DOM library, as a project sharing code with the web does, gets 69 errors in globals.d.ts from a plain import {View} from 'react-native'.

The generated declarations themselves import the Blob, FormData and ErrorUtils types they use by path, so the reference only adds these globals.

Steps to reproduce
  1. Clone https://github.com/YevheniiKotyrlo/react-native-typescript-declarations and run yarn install in ReproducerApp. It runs [email protected] with TypeScript 7.0.2 and @types/react 19.3.0.
  2. Run yarn check:dom. It type-checks declarations/import-react-native.ts, which is import {View} from 'react-native', with strict: true, skipLibCheck: false and lib: ["ES2024", "DOM", "DOM.Iterable"].

Expected: no errors from react-native's declarations.
Seen: 72 errors, 69 of them from the globals in src/types/globals.d.ts (TS2300, TS2403, TS2687, TS2717) and three from types_generated itself, which I reported in #59647. 0.88.1 prints the same 72.

React Native Version

0.88.1, and 0.89.0-nightly-20261029-25b05acd7

Affected Platforms

Other (please specify)

Output of npx @react-native-community/cli info
System:
  OS: Windows 11 10.0.26300
Binaries:
  Node:
    version: 26.12.1
  Yarn:
    version: 1.22.22
npmPackages:
  "@react-native-community/cli":
    installed: 20.2.0
    wanted: 20.2.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.89.0-nightly-20261029-25b05acd7
    wanted: 0.89.0-nightly-20261029-25b05acd7

The defect is in the published TypeScript declarations, so it shows on every platform; the reproducer only runs tsc.

Stacktrace or Logs

The first errors of yarn check:dom, cut at 200 characters:

node_modules/react-native/src/types/globals.d.ts(218,8): error TS2300: Duplicate identifier 'EndingType'.
node_modules/react-native/src/types/globals.d.ts(219,8): error TS2300: Duplicate identifier 'BlobPart'.
node_modules/react-native/src/types/globals.d.ts(220,8): error TS2300: Duplicate identifier 'BufferSource'.
node_modules/react-native/src/types/globals.d.ts(238,7): error TS2403: Subsequent variable declarations must have the same type.  Variable 'Blob' must be of type '{ new (blobParts?: BlobPart[] | undef
node_modules/react-native/src/types/globals.d.ts(252,7): error TS2403: Subsequent variable declarations must have the same type.  Variable 'File' must be of type '{ new (fileBits: BlobPart[], fileName
node_modules/react-native/src/types/globals.d.ts(273,9): error TS2300: Duplicate identifier 'FormData'.
node_modules/react-native/src/types/globals.d.ts(338,5): error TS2717: Subsequent property declarations must have the same type.  Property 'body' must be of type 'BodyInit | null | undefined', but her
node_modules/react-native/src/types/globals.d.ts(347,5): error TS2717: Subsequent property declarations must have the same type.  Property 'signal' must be of type 'AbortSignal | null | undefined', bu
node_modules/react-native/src/types/globals.d.ts(357,14): error TS2717: Subsequent property declarations must have the same type.  Property 'signal' must be of type 'AbortSignal', but here has type 'A
node_modules/react-native/src/types/globals.d.ts(361,7): error TS2403: Subsequent variable declarations must have the same type.  Variable 'Request' must be of type '{ new (input: URL | RequestInfo, i
node_modules/react-native/src/types/globals.d.ts(366,8): error TS2300: Duplicate identifier 'RequestInfo'.
node_modules/react-native/src/types/globals.d.ts(385,7): error TS2403: Subsequent variable declarations must have the same type.  Variable 'Response' must be of type '{ new (body?: BodyInit | null | u
node_modules/react-native/src/types/globals.d.ts(465,5): error TS2717: Subsequent property declarations must have the same type.  Property 'abort' must be of type 'ProgressEvent<XMLHttpRequestEventTar
node_modules/react-native/src/types/globals.d.ts(466,5): error TS2717: Subsequent property declarations must have the same type.  Property 'error' must be of type 'ProgressEvent<XMLHttpRequestEventTar
MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/react-native-typescript-declarations

Screenshots and Videos

None: the failure is the type checker's output above.

主要语言
C++
星标
127k
派生
25.4k
平均合并
2 天 9 小时
30 天内合并 PR
91

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

react/react-native 的其他 Issue

查看 react/react-native 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。