【问题标题】:How do I fix this flow < 0.114 error with react-native > 0.64?如何使用 react-native > 0.64 修复此流 < 0.114 错误?
【发布时间】: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


    【解决方案1】:

    我通过维护相同的流程版本并仅定义一个名为 symbol 的新类型来修复它。我必须在我的项目中创建此文件夹flow-typed,然后在其中创建一个名为myLibDef.js 的新文件并声明

    declare type symbol = any;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-21
      • 2019-09-18
      • 1970-01-01
      • 2021-04-01
      • 2018-06-28
      • 2020-11-16
      • 2019-04-23
      • 1970-01-01
      相关资源
      最近更新 更多