Estoy actualizando este proyecto nativo de reacción 0.64 a 0.67.
El proyecto utiliza flow como lenguaje de verificación de tipos. También lo estamos migrando a TypeScript, pero ese no es el alcance del error actual y es mejor que sigamos ejecutando el flow de la línea de comando para ver si los archivos de flujo existentes están bien escritos y sin errores.
Aparentemente, react-native se crea con verificación de tipo de flujo. Entonces, hay algunos tipos de flujo enviados dentro de react-native. El problema es que una declaración de tipo global.js usa un tipo de symbol que fue introducido solo por el flujo 0.114.
Nuestra versión actual flow-bin es 0.92.1. Si actualizamos el flujo, da cientos de errores. Y como estamos migrando a mecanografiado, no queremos actualizar el flujo.
El archivo global.js que presenta este error tiene el siguiente aspecto:
/** * 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, }; Entonces, cuando se ejecuta npm run flow , devuelve el siguiente error:
Cannot resolve name symbolLo arreglé manteniendo la misma versión de flujo y simplemente definiendo un nuevo tipo llamado symbol . Tuve que crear esta carpeta flow-typed en mi proyecto, luego un nuevo archivo dentro llamado myLibDef.js y declarar
declare type symbol = any;