【发布时间】:2022-02-04 04:15:57
【问题描述】:
我正在将这个 react-native 0.64 升级到 0.67 项目。
该项目使用flow 作为其类型检查语言。我们也在将其迁移到 typescript,但这不是当前错误的范围,我们最好继续运行命令行 flow 以查看现有流文件是否输入正确且没有错误。
显然 react-native 是通过流类型检查创建的。因此,在 react-native 中提供了一些流类型。问题是一个 global.js 类型声明使用了 symbol 类型,它仅由流 0.114 引入。
我们当前的flow-bin 版本是0.92.1。如果我们升级流程,它会产生数百个错误。当我们迁移到 typescript 时,我们不想升级流程。
引入此错误的 global.js 文件如下所示:
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
/**
* `global` is a object containing all the global variables for React Native.
*
* NOTE: Consider cross-platform as well as JS environments compatibility
* when defining the types here. Consider both presence (`?`) as well as
* writeability (`+`) when defining types.
*/
declare var global: {
// setUpGlobals
+window: typeof global,
+self: typeof global,
// setXHR
+XMLHttpRequest: typeof XMLHttpRequest,
+FormData: typeof FormData,
+fetch: typeof fetch,
+Headers: typeof Headers,
+Request: typeof Request,
+Response: typeof Response,
+WebSocket: typeof WebSocket,
+Blob: typeof Blob,
+File: typeof File,
+FileReader: typeof FileReader,
+URL: typeof URL,
+URLSearchParams: typeof URLSearchParams,
+AbortController: typeof AbortController,
+AbortSignal: typeof AbortSignal,
// setUpAlert
+alert: typeof alert,
// setUpTimers
+clearInterval: typeof clearInterval,
+clearTimeout: typeof clearTimeout,
+setInterval: typeof setInterval,
+setTimeout: typeof setTimeout,
+requestAnimationFrame: typeof requestAnimationFrame,
+cancelAnimationFrame: typeof cancelAnimationFrame,
+requestIdleCallback: typeof requestIdleCallback,
+cancelIdleCallback: typeof cancelIdleCallback,
+setTimeout: typeof setTimeout,
// TODO(T97509743): use `typeof` when the next Flow release is available.
+queueMicrotask: <TArguments: Array<mixed>>(
jobCallback: (...args: TArguments) => mixed,
) => void,
+console: typeof console,
// JavaScript environments specific
+HermesInternal: ?$HermesInternalType,
// Internal-specific
+__DEV__?: boolean,
+RN$Bridgeless?: boolean,
// Undeclared properties are implicitly `any`.
[string | symbol]: any,
};
所以在运行npm run flow 时会返回以下错误:
Cannot resolve name symbol
【问题讨论】:
标签: javascript react-native flowtype