diff --git a/Libraries/BatchedBridge/BatchedBridge.js b/Libraries/BatchedBridge/BatchedBridge.js index b68e9873e39..5b928edcc6b 100644 --- a/Libraries/BatchedBridge/BatchedBridge.js +++ b/Libraries/BatchedBridge/BatchedBridge.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/BatchedBridge/MessageQueue.js b/Libraries/BatchedBridge/MessageQueue.js index d68f2fd2cef..c1314d9ea79 100644 --- a/Libraries/BatchedBridge/MessageQueue.js +++ b/Libraries/BatchedBridge/MessageQueue.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ @@ -22,7 +22,7 @@ export type SpyData = { type: number, module: ?string, method: string | number, - args: any[], + args: mixed[], ... }; @@ -40,10 +40,10 @@ const TRACE_TAG_REACT_APPS = 1 << 17; const DEBUG_INFO_LIMIT = 32; class MessageQueue { - _lazyCallableModules: {[key: string]: (void) => Object, ...}; - _queue: [number[], number[], any[], number]; - _successCallbacks: Map; - _failureCallbacks: Map; + _lazyCallableModules: {[key: string]: (void) => {...}, ...}; + _queue: [number[], number[], mixed[], number]; + _successCallbacks: Map void>; + _failureCallbacks: Map void>; _callID: number; _lastFlush: number; _eventLoopStartTime: number; @@ -71,11 +71,15 @@ class MessageQueue { this._remoteMethodTable = {}; } - (this: any).callFunctionReturnFlushedQueue = this.callFunctionReturnFlushedQueue.bind( + // $FlowFixMe[cannot-write] + this.callFunctionReturnFlushedQueue = this.callFunctionReturnFlushedQueue.bind( this, ); - (this: any).flushedQueue = this.flushedQueue.bind(this); - (this: any).invokeCallbackAndReturnFlushedQueue = this.invokeCallbackAndReturnFlushedQueue.bind( + // $FlowFixMe[cannot-write] + this.flushedQueue = this.flushedQueue.bind(this); + + // $FlowFixMe[cannot-write] + this.invokeCallbackAndReturnFlushedQueue = this.invokeCallbackAndReturnFlushedQueue.bind( this, ); } @@ -89,7 +93,7 @@ class MessageQueue { MessageQueue.prototype.__spy = info => { console.log( `${info.type === TO_JS ? 'N->JS' : 'JS->N'} : ` + - `${info.module ? info.module + '.' : ''}${info.method}` + + `${info.module != null ? info.module + '.' : ''}${info.method}` + `(${JSON.stringify(info.args)})`, ); }; @@ -103,8 +107,8 @@ class MessageQueue { callFunctionReturnFlushedQueue( module: string, method: string, - args: any[], - ): null | [Array, Array, Array, number] { + args: mixed[], + ): null | [Array, Array, Array, number] { this.__guard(() => { this.__callFunction(module, method, args); }); @@ -114,8 +118,8 @@ class MessageQueue { invokeCallbackAndReturnFlushedQueue( cbID: number, - args: any[], - ): null | [Array, Array, Array, number] { + args: mixed[], + ): null | [Array, Array, Array, number] { this.__guard(() => { this.__invokeCallback(cbID, args); }); @@ -123,7 +127,7 @@ class MessageQueue { return this.flushedQueue(); } - flushedQueue(): null | [Array, Array, Array, number] { + flushedQueue(): null | [Array, Array, Array, number] { this.__guard(() => { this.__callImmediates(); }); @@ -137,13 +141,13 @@ class MessageQueue { return Date.now() - this._eventLoopStartTime; } - registerCallableModule(name: string, module: Object) { + registerCallableModule(name: string, module: {...}) { this._lazyCallableModules[name] = () => module; } - registerLazyCallableModule(name: string, factory: void => Object) { - let module: Object; - let getValue: ?(void) => Object = factory; + registerLazyCallableModule(name: string, factory: void => {...}) { + let module: {...}; + let getValue: ?(void) => {...} = factory; this._lazyCallableModules[name] = () => { if (getValue) { module = getValue(); @@ -153,7 +157,7 @@ class MessageQueue { }; } - getCallableModule(name: string): any | null { + getCallableModule(name: string): {...} | null { const getValue = this._lazyCallableModules[name]; return getValue ? getValue() : null; } @@ -161,10 +165,10 @@ class MessageQueue { callNativeSyncHook( moduleID: number, methodID: number, - params: any[], - onFail: ?Function, - onSucc: ?Function, - ): any { + params: mixed[], + onFail: ?(...mixed[]) => void, + onSucc: ?(...mixed[]) => void, + ): mixed { if (__DEV__) { invariant( global.nativeCallSyncHook, @@ -181,10 +185,10 @@ class MessageQueue { processCallbacks( moduleID: number, methodID: number, - params: any[], - onFail: ?Function, - onSucc: ?Function, - ) { + params: mixed[], + onFail: ?(...mixed[]) => void, + onSucc: ?(...mixed[]) => void, + ): void { if (onFail || onSucc) { if (__DEV__) { this._debugInfo[this._callID] = [moduleID, methodID]; @@ -232,9 +236,9 @@ class MessageQueue { enqueueNativeCall( moduleID: number, methodID: number, - params: any[], - onFail: ?Function, - onSucc: ?Function, + params: mixed[], + onFail: ?(...mixed[]) => void, + onSucc: ?(...mixed[]) => void, ) { this.processCallbacks(moduleID, methodID, params, onFail, onSucc); @@ -247,30 +251,34 @@ class MessageQueue { // function it is permitted here, and special-cased in the // conversion. const isValidArgument = val => { - const t = typeof val; - if ( - t === 'undefined' || - t === 'null' || - t === 'boolean' || - t === 'string' - ) { - return true; - } - if (t === 'number') { - return isFinite(val); - } - if (t === 'function' || t !== 'object') { - return false; - } - if (Array.isArray(val)) { - return val.every(isValidArgument); - } - for (const k in val) { - if (typeof val[k] !== 'function' && !isValidArgument(val[k])) { + switch (typeof val) { + case 'undefined': + case 'boolean': + case 'string': + return true; + case 'number': + return isFinite(val); + case 'object': + if (val == null) { + return true; + } + + if (Array.isArray(val)) { + return val.every(isValidArgument); + } + + for (const k in val) { + if (typeof val[k] !== 'function' && !isValidArgument(val[k])) { + return false; + } + } + + return true; + case 'function': + return false; + default: return false; - } } - return true; }; // Replacement allows normally non-JSON-convertible values to be @@ -295,7 +303,7 @@ class MessageQueue { ); // The params object should not be mutated after being queued - deepFreezeAndThrowOnMutationInDev((params: any)); + deepFreezeAndThrowOnMutationInDev(params); } this._queue[PARAMS].push(params); @@ -382,7 +390,7 @@ class MessageQueue { Systrace.endEvent(); } - __callFunction(module: string, method: string, args: any[]): void { + __callFunction(module: string, method: string, args: mixed[]): void { this._lastFlush = Date.now(); this._eventLoopStartTime = this._lastFlush; if (__DEV__ || this.__spy) { @@ -410,7 +418,7 @@ class MessageQueue { Systrace.endEvent(); } - __invokeCallback(cbID: number, args: any[]) { + __invokeCallback(cbID: number, args: mixed[]) { this._lastFlush = Date.now(); this._eventLoopStartTime = this._lastFlush; diff --git a/Libraries/BatchedBridge/NativeModules.js b/Libraries/BatchedBridge/NativeModules.js index 541012582c0..4f764463738 100644 --- a/Libraries/BatchedBridge/NativeModules.js +++ b/Libraries/BatchedBridge/NativeModules.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -18,7 +18,7 @@ import type {ExtendedError} from '../Core/Devtools/parseErrorStack'; export type ModuleConfig = [ string /* name */, - ?Object /* constants */, + ?{...} /* constants */, ?$ReadOnlyArray /* functions */, ?$ReadOnlyArray /* promise method IDs */, ?$ReadOnlyArray /* sync method IDs */, @@ -31,7 +31,7 @@ function genModule( moduleID: number, ): ?{ name: string, - module?: Object, + module?: {...}, ... } { if (!config) { @@ -55,8 +55,9 @@ function genModule( methods && methods.forEach((methodName, methodID) => { const isPromise = - promiseMethods && arrayContains(promiseMethods, methodID); - const isSync = syncMethods && arrayContains(syncMethods, methodID); + (promiseMethods && arrayContains(promiseMethods, methodID)) || false; + const isSync = + (syncMethods && arrayContains(syncMethods, methodID)) || false; invariant( !isPromise || !isSync, 'Cannot have a method that is both async and a sync hook', @@ -85,7 +86,7 @@ function genModule( // export this method as a global so we can call it from native global.__fbGenNativeModule = genModule; -function loadModule(name: string, moduleID: number): ?Object { +function loadModule(name: string, moduleID: number): ?{...} { invariant( global.nativeRequireModuleConfig, "Can't lazily create module without nativeRequireModuleConfig", @@ -98,7 +99,7 @@ function loadModule(name: string, moduleID: number): ?Object { function genMethod(moduleID: number, methodID: number, type: MethodType) { let fn = null; if (type === 'promise') { - fn = function promiseMethodWrapper(...args: Array) { + fn = function promiseMethodWrapper(...args: Array) { // In case we reject, capture a useful stack trace here. const enqueueingFrameError: ExtendedError = new Error(); return new Promise((resolve, reject) => { @@ -108,12 +109,17 @@ function genMethod(moduleID: number, methodID: number, type: MethodType) { args, data => resolve(data), errorData => - reject(updateErrorWithErrorData(errorData, enqueueingFrameError)), + reject( + updateErrorWithErrorData( + (errorData: $FlowFixMe), + enqueueingFrameError, + ), + ), ); }); }; } else { - fn = function nonPromiseMethodWrapper(...args: Array) { + fn = function nonPromiseMethodWrapper(...args: Array) { const lastArg = args.length > 0 ? args[args.length - 1] : null; const secondLastArg = args.length > 1 ? args[args.length - 2] : null; const hasSuccessCallback = typeof lastArg === 'function'; @@ -123,15 +129,17 @@ function genMethod(moduleID: number, methodID: number, type: MethodType) { hasSuccessCallback, 'Cannot have a non-function arg after a function arg.', ); - const onSuccess = hasSuccessCallback ? lastArg : null; - const onFail = hasErrorCallback ? secondLastArg : null; + // $FlowFixMe[incompatible-type] + const onSuccess: ?(mixed) => void = hasSuccessCallback ? lastArg : null; + // $FlowFixMe[incompatible-type] + const onFail: ?(mixed) => void = hasErrorCallback ? secondLastArg : null; const callbackCount = hasSuccessCallback + hasErrorCallback; - args = args.slice(0, args.length - callbackCount); + const newArgs = args.slice(0, args.length - callbackCount); if (type === 'sync') { return BatchedBridge.callNativeSyncHook( moduleID, methodID, - args, + newArgs, onFail, onSuccess, ); @@ -139,7 +147,7 @@ function genMethod(moduleID: number, methodID: number, type: MethodType) { BatchedBridge.enqueueNativeCall( moduleID, methodID, - args, + newArgs, onFail, onSuccess, ); @@ -161,7 +169,7 @@ function updateErrorWithErrorData( return Object.assign(error, errorData || {}); } -let NativeModules: {[moduleName: string]: Object, ...} = {}; +let NativeModules: {[moduleName: string]: $FlowFixMe, ...} = {}; if (global.nativeModuleProxy) { NativeModules = global.nativeModuleProxy; } else if (!global.nativeExtensions) { diff --git a/Libraries/Blob/Blob.js b/Libraries/Blob/Blob.js index 2af35f2bcb0..99d5e59b8e5 100644 --- a/Libraries/Blob/Blob.js +++ b/Libraries/Blob/Blob.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict-local * @format */ @@ -67,10 +67,12 @@ class Blob { * the data in the specified range of bytes of the source Blob. * Reference: https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice */ + // $FlowFixMe[unsafe-getters-setters] set data(data: ?BlobData) { this._data = data; } + // $FlowFixMe[unsafe-getters-setters] get data(): BlobData { if (!this._data) { throw new Error('Blob has been closed and is no longer available'); @@ -85,6 +87,7 @@ class Blob { if (typeof start === 'number') { if (start > size) { + // $FlowFixMe[reassign-const] start = size; } offset += start; @@ -92,6 +95,7 @@ class Blob { if (typeof end === 'number') { if (end < 0) { + // $FlowFixMe[reassign-const] end = this.size + end; } size = end - start; @@ -125,6 +129,7 @@ class Blob { /** * Size of the data contained in the Blob object, in bytes. */ + // $FlowFixMe[unsafe-getters-setters] get size(): number { return this.data.size; } @@ -133,6 +138,7 @@ class Blob { * String indicating the MIME type of the data contained in the Blob. * If the type is unknown, this string is empty. */ + // $FlowFixMe[unsafe-getters-setters] get type(): string { return this.data.type || ''; } diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js index 3c77eb3c9f3..b0909d2b072 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.android.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -90,6 +90,7 @@ const AccessibilityInfo = { * * Same as `isScreenReaderEnabled` */ + // $FlowFixMe[unsafe-getters-setters] get fetch(): () => Promise { console.warn( 'AccessibilityInfo.fetch is deprecated, call AccessibilityInfo.isScreenReaderEnabled instead', @@ -97,34 +98,27 @@ const AccessibilityInfo = { return this.isScreenReaderEnabled; }, - addEventListener: function( - eventName: ChangeEventName, - handler: Function, - ): void { + addEventListener: function(eventName: ChangeEventName, handler: T): void { let listener; if (eventName === 'change' || eventName === 'screenReaderChanged') { listener = RCTDeviceEventEmitter.addListener( TOUCH_EXPLORATION_EVENT, - enabled => { - handler(enabled); - }, + handler, ); } else if (eventName === 'reduceMotionChanged') { listener = RCTDeviceEventEmitter.addListener( REDUCE_MOTION_EVENT, - enabled => { - handler(enabled); - }, + handler, ); } _subscriptions.set(handler, listener); }, - removeEventListener: function( + removeEventListener: function( eventName: ChangeEventName, - handler: Function, + handler: T, ): void { const listener = _subscriptions.get(handler); if (!listener) { diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js index 6df67ffaebb..fb73ab2ee24 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -163,6 +163,7 @@ const AccessibilityInfo = { * * Same as `isScreenReaderEnabled` */ + // $FlowFixMe[unsafe-getters-setters] get fetch(): $FlowFixMe { console.warn( 'AccessibilityInfo.fetch is deprecated, call AccessibilityInfo.isScreenReaderEnabled instead', @@ -201,10 +202,10 @@ const AccessibilityInfo = { * * See https://reactnative.dev/docs/accessibilityinfo.html#addeventlistener */ - addEventListener: function( + addEventListener: function( eventName: ChangeEventName, - handler: Function, - ): Object { + handler: T, + ): {remove: () => void} { let listener; if (eventName === 'change') { @@ -253,9 +254,9 @@ const AccessibilityInfo = { * * See https://reactnative.dev/docs/accessibilityinfo.html#removeeventlistener */ - removeEventListener: function( + removeEventListener: function( eventName: ChangeEventName, - handler: Function, + handler: T, ): void { const listener = _subscriptions.get(handler); if (!listener) { diff --git a/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js b/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js index 10aa0f110cd..03484f2158c 100644 --- a/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js +++ b/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js b/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js index 3cecc6e84e7..26f9f801679 100644 --- a/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js +++ b/Libraries/Components/AppleTV/NativeTVNavigationEventEmitter.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Components/Clipboard/Clipboard.js b/Libraries/Components/Clipboard/Clipboard.js index d58b2285473..fa0b9a050d4 100644 --- a/Libraries/Components/Clipboard/Clipboard.js +++ b/Libraries/Components/Clipboard/Clipboard.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Components/Clipboard/NativeClipboard.js b/Libraries/Components/Clipboard/NativeClipboard.js index 35bfa11851c..b585a108e04 100644 --- a/Libraries/Components/Clipboard/NativeClipboard.js +++ b/Libraries/Components/Clipboard/NativeClipboard.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Components/Keyboard/NativeKeyboardObserver.js b/Libraries/Components/Keyboard/NativeKeyboardObserver.js index b6ef87b4d3a..7f077c3c88b 100644 --- a/Libraries/Components/Keyboard/NativeKeyboardObserver.js +++ b/Libraries/Components/Keyboard/NativeKeyboardObserver.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Components/Sound/NativeSoundManager.js b/Libraries/Components/Sound/NativeSoundManager.js index b5b72ac4959..d278168552f 100644 --- a/Libraries/Components/Sound/NativeSoundManager.js +++ b/Libraries/Components/Sound/NativeSoundManager.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Components/Sound/SoundManager.js b/Libraries/Components/Sound/SoundManager.js index 943b4c5c535..0e63332728f 100644 --- a/Libraries/Components/Sound/SoundManager.js +++ b/Libraries/Components/Sound/SoundManager.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js b/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js index ee25f79cf37..5b00b2a4c21 100644 --- a/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js +++ b/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js b/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js index 9840e3da2d4..b5da2851bf2 100644 --- a/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js +++ b/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Components/ToastAndroid/NativeToastAndroid.js b/Libraries/Components/ToastAndroid/NativeToastAndroid.js index d4039be72f3..97f70204e9b 100644 --- a/Libraries/Components/ToastAndroid/NativeToastAndroid.js +++ b/Libraries/Components/ToastAndroid/NativeToastAndroid.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/Devtools/getDevServer.js b/Libraries/Core/Devtools/getDevServer.js index c60d0e51606..97c7c72468c 100644 --- a/Libraries/Core/Devtools/getDevServer.js +++ b/Libraries/Core/Devtools/getDevServer.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -36,7 +36,7 @@ function getDevServer(): DevServerInfo { } return { - url: _cachedDevServerURL || FALLBACK, + url: _cachedDevServerURL ?? FALLBACK, fullBundleUrl: _cachedFullBundleURL, bundleLoadedFromServer: _cachedDevServerURL !== null, }; diff --git a/Libraries/Core/Devtools/openFileInEditor.js b/Libraries/Core/Devtools/openFileInEditor.js index 4d52b3f4ff7..66dca4721b9 100644 --- a/Libraries/Core/Devtools/openFileInEditor.js +++ b/Libraries/Core/Devtools/openFileInEditor.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Core/Devtools/openURLInBrowser.js b/Libraries/Core/Devtools/openURLInBrowser.js index e69dc57183f..d4b00663aaf 100644 --- a/Libraries/Core/Devtools/openURLInBrowser.js +++ b/Libraries/Core/Devtools/openURLInBrowser.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Core/Devtools/parseErrorStack.js b/Libraries/Core/Devtools/parseErrorStack.js index ec69f3f69cf..3df85895ab7 100644 --- a/Libraries/Core/Devtools/parseErrorStack.js +++ b/Libraries/Core/Devtools/parseErrorStack.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; diff --git a/Libraries/Core/Devtools/parseHermesStack.js b/Libraries/Core/Devtools/parseHermesStack.js index 7aa91caf5d3..9d3ba2f9284 100644 --- a/Libraries/Core/Devtools/parseHermesStack.js +++ b/Libraries/Core/Devtools/parseHermesStack.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Core/Devtools/symbolicateStackTrace.js b/Libraries/Core/Devtools/symbolicateStackTrace.js index ef128990867..7a6b8cd80ce 100644 --- a/Libraries/Core/Devtools/symbolicateStackTrace.js +++ b/Libraries/Core/Devtools/symbolicateStackTrace.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -53,6 +53,7 @@ async function symbolicateStackTrace( // The fix below postpones trying to load fetch until the first call to symbolicateStackTrace. // At that time, we will have either global.fetch (whatwg-fetch) or RN's fetch. if (!fetch) { + // flowlint-next-line untyped-import:off fetch = global.fetch || require('../../Network/fetch').fetch; } diff --git a/Libraries/Core/NativeExceptionsManager.js b/Libraries/Core/NativeExceptionsManager.js index b47dc42f3e6..10b7b77e08e 100644 --- a/Libraries/Core/NativeExceptionsManager.js +++ b/Libraries/Core/NativeExceptionsManager.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/ReactNativeVersion.js b/Libraries/Core/ReactNativeVersion.js index 1fcb2e9eb61..67ca7cd62bc 100644 --- a/Libraries/Core/ReactNativeVersion.js +++ b/Libraries/Core/ReactNativeVersion.js @@ -6,7 +6,7 @@ * * @format * @generated by scripts/bump-oss-version.js - * @flow + * @flow strict */ exports.version = { diff --git a/Libraries/Core/ReactNativeVersionCheck.js b/Libraries/Core/ReactNativeVersionCheck.js index 263d8794f0f..5958842b30f 100644 --- a/Libraries/Core/ReactNativeVersionCheck.js +++ b/Libraries/Core/ReactNativeVersionCheck.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js b/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js index 63df69cfbb3..8baeee3d4c1 100644 --- a/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js +++ b/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/Timers/NativeTiming.js b/Libraries/Core/Timers/NativeTiming.js index 14d03d52cfd..53477dd6584 100644 --- a/Libraries/Core/Timers/NativeTiming.js +++ b/Libraries/Core/Timers/NativeTiming.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/polyfillPromise.js b/Libraries/Core/polyfillPromise.js index f7375ab1ee8..b15ccc2b301 100644 --- a/Libraries/Core/polyfillPromise.js +++ b/Libraries/Core/polyfillPromise.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/setUpGlobals.js b/Libraries/Core/setUpGlobals.js index 5acc42ae794..ea6da8fbbbe 100644 --- a/Libraries/Core/setUpGlobals.js +++ b/Libraries/Core/setUpGlobals.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/setUpNavigator.js b/Libraries/Core/setUpNavigator.js index 74f58695ad6..48cdd45cb1d 100644 --- a/Libraries/Core/setUpNavigator.js +++ b/Libraries/Core/setUpNavigator.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/setUpPerformance.js b/Libraries/Core/setUpPerformance.js index 6fd0a1e42b8..12cace05f81 100644 --- a/Libraries/Core/setUpPerformance.js +++ b/Libraries/Core/setUpPerformance.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Core/setUpSystrace.js b/Libraries/Core/setUpSystrace.js index dc50797f310..610324b440e 100644 --- a/Libraries/Core/setUpSystrace.js +++ b/Libraries/Core/setUpSystrace.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/HeapCapture/HeapCapture.js b/Libraries/HeapCapture/HeapCapture.js index 903343a05b0..d48368d8aa1 100644 --- a/Libraries/HeapCapture/HeapCapture.js +++ b/Libraries/HeapCapture/HeapCapture.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/HeapCapture/NativeJSCHeapCapture.js b/Libraries/HeapCapture/NativeJSCHeapCapture.js index 05e941f17e7..0605cd119e0 100644 --- a/Libraries/HeapCapture/NativeJSCHeapCapture.js +++ b/Libraries/HeapCapture/NativeJSCHeapCapture.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Image/NativeImageEditor.js b/Libraries/Image/NativeImageEditor.js index 19dbf3cb6e5..c6fdc63f7d4 100644 --- a/Libraries/Image/NativeImageEditor.js +++ b/Libraries/Image/NativeImageEditor.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Image/NativeImagePickerIOS.js b/Libraries/Image/NativeImagePickerIOS.js index 4db17f4059a..fa64998c57b 100644 --- a/Libraries/Image/NativeImagePickerIOS.js +++ b/Libraries/Image/NativeImagePickerIOS.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Image/NativeImageStore.js b/Libraries/Image/NativeImageStore.js index cbd7b22fd02..38603b6aaab 100644 --- a/Libraries/Image/NativeImageStore.js +++ b/Libraries/Image/NativeImageStore.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Interaction/InteractionManager.js b/Libraries/Interaction/InteractionManager.js index c438a67e7a9..8aec6727e33 100644 --- a/Libraries/Interaction/InteractionManager.js +++ b/Libraries/Interaction/InteractionManager.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -88,13 +88,16 @@ const InteractionManager = { runAfterInteractions( task: ?Task, ): { - then: Function, - done: Function, - cancel: Function, + then: ( + onFulfill?: ?(void) => ?(Promise | U), + onReject?: ?(error: mixed) => ?(Promise | U), + ) => Promise, + done: () => void, + cancel: () => void, ... } { - const tasks = []; - const promise = new Promise(resolve => { + const tasks: Array = []; + const promise = new Promise((resolve: () => void) => { _scheduleUpdate(); if (task) { tasks.push(task); @@ -164,8 +167,6 @@ let _nextUpdateHandle = 0; let _inc = 0; let _deadline = -1; -declare function setImmediate(callback: any, ...args: Array): number; - /** * Schedule an asynchronous update to the interaction state. */ diff --git a/Libraries/Interaction/NativeFrameRateLogger.js b/Libraries/Interaction/NativeFrameRateLogger.js index d248a7cf3cb..363294aed75 100644 --- a/Libraries/Interaction/NativeFrameRateLogger.js +++ b/Libraries/Interaction/NativeFrameRateLogger.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ import type {TurboModule} from '../TurboModule/RCTExport'; diff --git a/Libraries/Interaction/TaskQueue.js b/Libraries/Interaction/TaskQueue.js index 15eb69388dc..965953f64fb 100644 --- a/Libraries/Interaction/TaskQueue.js +++ b/Libraries/Interaction/TaskQueue.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -16,14 +16,12 @@ const invariant = require('invariant'); type SimpleTask = { name: string, run: () => void, - ... }; type PromiseTask = { name: string, - gen: () => Promise, - ... + gen: () => Promise, }; -export type Task = Function | SimpleTask | PromiseTask; +export type Task = SimpleTask | PromiseTask | (() => void); const DEBUG: false = false; @@ -101,10 +99,10 @@ class TaskQueue { if (queue.length) { const task = queue.shift(); try { - if (task.gen) { + if (typeof task === 'object' && task.gen) { DEBUG && infoLog('TaskQueue: genPromise for task ' + task.name); - this._genPromise((task: any)); // Rather than annoying tagged union - } else if (task.run) { + this._genPromise(task); + } else if (typeof task === 'object' && task.run) { DEBUG && infoLog('TaskQueue: run task ' + task.name); task.run(); } else { diff --git a/Libraries/JSInspector/InspectorAgent.js b/Libraries/JSInspector/InspectorAgent.js index b3bd4613143..8c12d695293 100644 --- a/Libraries/JSInspector/InspectorAgent.js +++ b/Libraries/JSInspector/InspectorAgent.js @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; -export type EventSender = (name: string, params: Object) => void; +export type EventSender = (name: string, params: mixed) => void; class InspectorAgent { _eventSender: EventSender; @@ -19,7 +19,7 @@ class InspectorAgent { this._eventSender = eventSender; } - sendEvent(name: string, params: Object) { + sendEvent(name: string, params: mixed) { this._eventSender(name, params); } } diff --git a/Libraries/JSInspector/JSInspector.js b/Libraries/JSInspector/JSInspector.js index 44917ac36b1..d4c8815ebe1 100644 --- a/Libraries/JSInspector/JSInspector.js +++ b/Libraries/JSInspector/JSInspector.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/JSInspector/NetworkAgent.js b/Libraries/JSInspector/NetworkAgent.js index 9f48f7cb1f2..f1811978709 100644 --- a/Libraries/JSInspector/NetworkAgent.js +++ b/Libraries/JSInspector/NetworkAgent.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -22,7 +22,7 @@ type LoaderId = string; type FrameId = string; type Timestamp = number; -type Headers = Object; +type Headers = {[string]: string}; // We don't currently care about this type ResourceTiming = null; @@ -160,7 +160,7 @@ class Interceptor { return this._requests.get(requestId); } - requestSent(id: number, url: string, method: string, headers: Object) { + requestSent(id: number, url: string, method: string, headers: Headers) { const requestId = String(id); this._requests.set(requestId, ''); @@ -188,7 +188,7 @@ class Interceptor { this._agent.sendEvent('requestWillBeSent', event); } - responseReceived(id: number, url: string, status: number, headers: Object) { + responseReceived(id: number, url: string, status: number, headers: Headers) { const requestId = String(id); const response: Response = { url, @@ -247,7 +247,7 @@ class Interceptor { this._agent.sendEvent('loadingFailed', event); } - _getMimeType(headers: Object): string { + _getMimeType(headers: Headers): string { const contentType = headers['Content-Type'] || ''; return contentType.split(';')[0]; } diff --git a/Libraries/LayoutAnimation/LayoutAnimation.js b/Libraries/LayoutAnimation/LayoutAnimation.js index 159b2b96c78..d68c0b14a04 100644 --- a/Libraries/LayoutAnimation/LayoutAnimation.js +++ b/Libraries/LayoutAnimation/LayoutAnimation.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict-local * @format */ @@ -23,9 +23,11 @@ import Platform from '../Utilities/Platform'; // Reexport type export type LayoutAnimationConfig = LayoutAnimationConfig_; +type OnAnimationDidEndCallback = () => void; + function configureNext( config: LayoutAnimationConfig, - onAnimationDidEnd?: Function, + onAnimationDidEnd?: OnAnimationDidEndCallback, ) { if (!Platform.isTesting) { if (UIManager?.configureNextLayoutAnimation) { @@ -131,13 +133,13 @@ const LayoutAnimation = { }, Presets, easeInEaseOut: (configureNext.bind(null, Presets.easeInEaseOut): ( - onAnimationDidEnd?: any, + onAnimationDidEnd?: OnAnimationDidEndCallback, ) => void), linear: (configureNext.bind(null, Presets.linear): ( - onAnimationDidEnd?: any, + onAnimationDidEnd?: OnAnimationDidEndCallback, ) => void), spring: (configureNext.bind(null, Presets.spring): ( - onAnimationDidEnd?: any, + onAnimationDidEnd?: OnAnimationDidEndCallback, ) => void), }; diff --git a/Libraries/Linking/Linking.js b/Libraries/Linking/Linking.js index 7a0ab925a6d..1ce5a8ae079 100644 --- a/Libraries/Linking/Linking.js +++ b/Libraries/Linking/Linking.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -33,7 +33,7 @@ class Linking extends NativeEventEmitter { * * See https://reactnative.dev/docs/linking.html#addeventlistener */ - addEventListener(type: string, handler: Function) { + addEventListener(type: string, handler: T) { this.addListener(type, handler); } @@ -42,7 +42,7 @@ class Linking extends NativeEventEmitter { * * See https://reactnative.dev/docs/linking.html#removeeventlistener */ - removeEventListener(type: string, handler: Function) { + removeEventListener(type: string, handler: T) { this.removeListener(type, handler); } @@ -51,7 +51,7 @@ class Linking extends NativeEventEmitter { * * See https://reactnative.dev/docs/linking.html#openurl */ - openURL(url: string): Promise { + openURL(url: string): Promise { this._validateURL(url); return NativeLinking.openURL(url); } @@ -71,7 +71,7 @@ class Linking extends NativeEventEmitter { * * See https://reactnative.dev/docs/linking.html#opensettings */ - openSettings(): Promise { + openSettings(): Promise { return NativeLinking.openSettings(); } diff --git a/Libraries/Linking/NativeLinking.js b/Libraries/Linking/NativeLinking.js index 18b3e7128cd..942aa4f01b8 100644 --- a/Libraries/Linking/NativeLinking.js +++ b/Libraries/Linking/NativeLinking.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index caefe6a3dc5..89523ad5d9b 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -175,7 +175,7 @@ class Modal extends React.Component { if ( props.presentationStyle && props.presentationStyle !== 'overFullScreen' && - props.transparent + props.transparent === true ) { console.warn( `Modal with '${props.presentationStyle}' presentation style and 'transparent' value is not supported.`, @@ -189,7 +189,8 @@ class Modal extends React.Component { } const containerStyles = { - backgroundColor: this.props.transparent ? 'transparent' : 'white', + backgroundColor: + this.props.transparent === true ? 'transparent' : 'white', }; let animationType = this.props.animationType || 'none'; @@ -197,7 +198,7 @@ class Modal extends React.Component { let presentationStyle = this.props.presentationStyle; if (!presentationStyle) { presentationStyle = 'fullScreen'; - if (this.props.transparent) { + if (this.props.transparent === true) { presentationStyle = 'overFullScreen'; } } diff --git a/Libraries/Modal/NativeModalManager.js b/Libraries/Modal/NativeModalManager.js index 159e095b9a4..05fc5b2c73c 100644 --- a/Libraries/Modal/NativeModalManager.js +++ b/Libraries/Modal/NativeModalManager.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js b/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js index bb784a616cd..55c24c1f9d1 100644 --- a/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js +++ b/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/NativeModules/specs/NativeDevMenu.js b/Libraries/NativeModules/specs/NativeDevMenu.js index 8d3880c739b..20b858a1c7d 100644 --- a/Libraries/NativeModules/specs/NativeDevMenu.js +++ b/Libraries/NativeModules/specs/NativeDevMenu.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/NativeModules/specs/NativeDevSettings.js b/Libraries/NativeModules/specs/NativeDevSettings.js index 48c155886cf..44acbd3a50b 100644 --- a/Libraries/NativeModules/specs/NativeDevSettings.js +++ b/Libraries/NativeModules/specs/NativeDevSettings.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/NativeModules/specs/NativeDeviceEventManager.js b/Libraries/NativeModules/specs/NativeDeviceEventManager.js index 342115dd0e4..775767e7275 100644 --- a/Libraries/NativeModules/specs/NativeDeviceEventManager.js +++ b/Libraries/NativeModules/specs/NativeDeviceEventManager.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js b/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js index 4ca12692fa1..fcc476b3419 100644 --- a/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js +++ b/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/NativeModules/specs/NativeLogBox.js b/Libraries/NativeModules/specs/NativeLogBox.js index 6d89481c390..782d1b078d4 100644 --- a/Libraries/NativeModules/specs/NativeLogBox.js +++ b/Libraries/NativeModules/specs/NativeLogBox.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ diff --git a/Libraries/NativeModules/specs/NativeSourceCode.js b/Libraries/NativeModules/specs/NativeSourceCode.js index 903123c94da..b1fb30fc292 100644 --- a/Libraries/NativeModules/specs/NativeSourceCode.js +++ b/Libraries/NativeModules/specs/NativeSourceCode.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Network/FormData.js b/Libraries/Network/FormData.js index bdb1da311da..8ff36068869 100644 --- a/Libraries/Network/FormData.js +++ b/Libraries/Network/FormData.js @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; -type FormDataValue = any; +type FormDataValue = string | {name?: string, type?: string, uri: string}; type FormDataNameValuePair = [string, FormDataValue]; type Headers = {[name: string]: string, ...}; diff --git a/Libraries/Network/RCTNetworking.ios.js b/Libraries/Network/RCTNetworking.ios.js index ec3706bf0ec..92ef3339431 100644 --- a/Libraries/Network/RCTNetworking.ios.js +++ b/Libraries/Network/RCTNetworking.ios.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -25,7 +25,7 @@ class RCTNetworking extends NativeEventEmitter { method: string, trackingName: string, url: string, - headers: Object, + headers: {...}, data: RequestBody, responseType: NativeResponseType, incrementalUpdates: boolean, diff --git a/Libraries/Performance/NativeJSCSamplingProfiler.js b/Libraries/Performance/NativeJSCSamplingProfiler.js index 519656d9d08..9ef08c96159 100644 --- a/Libraries/Performance/NativeJSCSamplingProfiler.js +++ b/Libraries/Performance/NativeJSCSamplingProfiler.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Performance/PureComponentDebug.js b/Libraries/Performance/PureComponentDebug.js index 982ed49353c..767a0d48727 100644 --- a/Libraries/Performance/PureComponentDebug.js +++ b/Libraries/Performance/PureComponentDebug.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ @@ -27,7 +27,7 @@ opaque type DoNotCommitUsageOfPureComponentDebug = {...}; */ class PureComponentDebug< P: DoNotCommitUsageOfPureComponentDebug, - S: ?Object = void, + S: ?{...} = void, > extends React.Component { shouldComponentUpdate(nextProps: P, nextState: S): boolean { const tag = this.constructor.name; diff --git a/Libraries/Performance/SamplingProfiler.js b/Libraries/Performance/SamplingProfiler.js index 2808f83ebdd..a1c0ece4d16 100644 --- a/Libraries/Performance/SamplingProfiler.js +++ b/Libraries/Performance/SamplingProfiler.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Performance/Systrace.js b/Libraries/Performance/Systrace.js index e1db39bbfc5..048c3d40427 100644 --- a/Libraries/Performance/Systrace.js +++ b/Libraries/Performance/Systrace.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ @@ -138,11 +138,18 @@ const Systrace = { /** * beginEvent/endEvent for starting and then ending a profile within the same call stack frame **/ - beginEvent(profileName?: any, args?: any) { + beginEvent( + profileName?: string | (() => string), + args?: {[string]: string, ...}, + ) { if (_enabled) { - profileName = + const profileNameString = typeof profileName === 'function' ? profileName() : profileName; - global.nativeTraceBeginSection(TRACE_TAG_REACT_APPS, profileName, args); + global.nativeTraceBeginSection( + TRACE_TAG_REACT_APPS, + profileNameString, + args, + ); } }, @@ -157,28 +164,28 @@ const Systrace = { * occur on another thread or out of the current stack frame, eg await * the returned cookie variable should be used as input into the endAsyncEvent call to end the profile **/ - beginAsyncEvent(profileName?: any): any { + beginAsyncEvent(profileName?: string | (() => string)): number { const cookie = _asyncCookie; if (_enabled) { _asyncCookie++; - profileName = + const profileNameString = typeof profileName === 'function' ? profileName() : profileName; global.nativeTraceBeginAsyncSection( TRACE_TAG_REACT_APPS, - profileName, + profileNameString, cookie, ); } return cookie; }, - endAsyncEvent(profileName?: any, cookie?: any) { + endAsyncEvent(profileName?: string | (() => string), cookie?: number) { if (_enabled) { - profileName = + const profileNameString = typeof profileName === 'function' ? profileName() : profileName; global.nativeTraceEndAsyncSection( TRACE_TAG_REACT_APPS, - profileName, + profileNameString, cookie, ); } @@ -187,12 +194,16 @@ const Systrace = { /** * counterEvent registers the value to the profileName on the systrace timeline **/ - counterEvent(profileName?: any, value?: any) { + counterEvent(profileName?: string | (() => string), value?: number) { if (_enabled) { - profileName = + const profileNameString = typeof profileName === 'function' ? profileName() : profileName; global.nativeTraceCounter && - global.nativeTraceCounter(TRACE_TAG_REACT_APPS, profileName, value); + global.nativeTraceCounter( + TRACE_TAG_REACT_APPS, + profileNameString, + value, + ); } }, }; @@ -202,7 +213,7 @@ if (__DEV__) { // other files. Therefore, calls to `require('moduleId')` are not replaced // with numeric IDs // TODO(davidaurelio) Scan polyfills for dependencies, too (t9759686) - (require: any).Systrace = Systrace; + (require: $FlowFixMe).Systrace = Systrace; } module.exports = Systrace; diff --git a/Libraries/PermissionsAndroid/NativePermissionsAndroid.js b/Libraries/PermissionsAndroid/NativePermissionsAndroid.js index 14aba8f1116..2e834fc725c 100644 --- a/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +++ b/Libraries/PermissionsAndroid/NativePermissionsAndroid.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/PermissionsAndroid/PermissionsAndroid.js b/Libraries/PermissionsAndroid/PermissionsAndroid.js index 83124ccc24b..d99ccd5ec83 100644 --- a/Libraries/PermissionsAndroid/PermissionsAndroid.js +++ b/Libraries/PermissionsAndroid/PermissionsAndroid.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Pressability/HoverState.js b/Libraries/Pressability/HoverState.js index df15f610993..ab9febf2b36 100644 --- a/Libraries/Pressability/HoverState.js +++ b/Libraries/Pressability/HoverState.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Promise.js b/Libraries/Promise.js index 292bc270744..836c2978a73 100644 --- a/Libraries/Promise.js +++ b/Libraries/Promise.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -18,25 +18,29 @@ require('promise/setimmediate/finally'); if (__DEV__) { require('promise/setimmediate/rejection-tracking').enable({ allRejections: true, - onUnhandled: (id, error = {}) => { + onUnhandled: (id, rejection = {}) => { let message: string; let stack: ?string; - const stringValue = Object.prototype.toString.call(error); + const stringValue = Object.prototype.toString.call(rejection); if (stringValue === '[object Error]') { - message = Error.prototype.toString.call(error); + message = Error.prototype.toString.call(rejection); + const error: Error = (rejection: $FlowFixMe); stack = error.stack; } else { try { - message = require('pretty-format')(error); + message = require('pretty-format')(rejection); } catch { - message = typeof error === 'string' ? error : JSON.stringify(error); + message = + typeof rejection === 'string' + ? rejection + : JSON.stringify((rejection: $FlowFixMe)); } } const warning = `Possible Unhandled Promise Rejection (id: ${id}):\n` + - `${message}\n` + + `${message ?? ''}\n` + (stack == null ? '' : stack); console.warn(warning); }, diff --git a/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js b/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js index 8cd05cf3afb..45f25deb211 100644 --- a/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js +++ b/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/ReactNative/NativeI18nManager.js b/Libraries/ReactNative/NativeI18nManager.js index e16db811e62..28933d510b3 100644 --- a/Libraries/ReactNative/NativeI18nManager.js +++ b/Libraries/ReactNative/NativeI18nManager.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/ReactNative/UIManagerProperties.js b/Libraries/ReactNative/UIManagerProperties.js index 938e42eef9d..77e67267e57 100644 --- a/Libraries/ReactNative/UIManagerProperties.js +++ b/Libraries/ReactNative/UIManagerProperties.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Share/NativeShareModule.js b/Libraries/Share/NativeShareModule.js index 88293b8ce87..08d313d76d7 100644 --- a/Libraries/Share/NativeShareModule.js +++ b/Libraries/Share/NativeShareModule.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Share/Share.js b/Libraries/Share/Share.js index aed341e56d0..5dad4772b7e 100644 --- a/Libraries/Share/Share.js +++ b/Libraries/Share/Share.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -74,7 +74,10 @@ class Share { * - `dialogTitle` * */ - static share(content: Content, options: Options = {}): Promise { + static share( + content: Content, + options: Options = {}, + ): Promise<{action: string, activityType: ?string}> { invariant( typeof content === 'object' && content !== null, 'Content to share must be a valid object', @@ -94,7 +97,7 @@ class Share { 'ShareModule should be registered on Android.', ); invariant( - !content.title || typeof content.title === 'string', + content.title == null || typeof content.title === 'string', 'Invalid title: title should be a string.', ); @@ -104,7 +107,12 @@ class Share { typeof content.message === 'string' ? content.message : undefined, }; - return NativeShareModule.share(newContent, options.dialogTitle); + return NativeShareModule.share(newContent, options.dialogTitle).then( + result => ({ + activityType: null, + ...result, + }), + ); } else if (Platform.OS === 'ios') { return new Promise((resolve, reject) => { const tintColor = processColor(options.tintColor); @@ -138,6 +146,7 @@ class Share { } else { resolve({ action: 'dismissedAction', + activityType: null, }); } }, diff --git a/Libraries/Storage/NativeAsyncStorage.js b/Libraries/Storage/NativeAsyncStorage.js index c67d291d034..539adfd80dc 100644 --- a/Libraries/Storage/NativeAsyncStorage.js +++ b/Libraries/Storage/NativeAsyncStorage.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/TurboModule/TurboModuleRegistry.js b/Libraries/TurboModule/TurboModuleRegistry.js index b3b1135f98b..1f06b8271a6 100644 --- a/Libraries/TurboModule/TurboModuleRegistry.js +++ b/Libraries/TurboModule/TurboModuleRegistry.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ @@ -22,7 +22,7 @@ export function get(name: string): ?T { // Backward compatibility layer during migration. const legacyModule = NativeModules[name]; if (legacyModule != null) { - return ((legacyModule: any): T); + return ((legacyModule: $FlowFixMe): T); } } diff --git a/Libraries/UTFSequence.js b/Libraries/UTFSequence.js index 70d17a3ba40..65a548df756 100644 --- a/Libraries/UTFSequence.js +++ b/Libraries/UTFSequence.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Utilities/Appearance.js b/Libraries/Utilities/Appearance.js index b63ff33c700..314b3eaaad6 100644 --- a/Libraries/Utilities/Appearance.js +++ b/Libraries/Utilities/Appearance.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; diff --git a/Libraries/Utilities/BackHandler.android.js b/Libraries/Utilities/BackHandler.android.js index ed5bb00d96a..e762c1635f9 100644 --- a/Libraries/Utilities/BackHandler.android.js +++ b/Libraries/Utilities/BackHandler.android.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict-local * @format */ diff --git a/Libraries/Utilities/BackHandler.ios.js b/Libraries/Utilities/BackHandler.ios.js index f7ed0515f2d..1407a57e95f 100644 --- a/Libraries/Utilities/BackHandler.ios.js +++ b/Libraries/Utilities/BackHandler.ios.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict-local * @format */ @@ -111,12 +111,15 @@ if (Platform.isTV) { } else { BackHandler = { exitApp: emptyFunction, - addEventListener(_eventName: BackPressEventName, _handler: Function) { + addEventListener(_eventName: BackPressEventName, _handler: () => ?boolean) { return { remove: emptyFunction, }; }, - removeEventListener(_eventName: BackPressEventName, _handler: Function) {}, + removeEventListener( + _eventName: BackPressEventName, + _handler: () => ?boolean, + ) {}, }; } diff --git a/Libraries/Utilities/DevSettings.js b/Libraries/Utilities/DevSettings.js index 42ffec85148..58494938ec6 100644 --- a/Libraries/Utilities/DevSettings.js +++ b/Libraries/Utilities/DevSettings.js @@ -5,12 +5,19 @@ * LICENSE file in the root directory of this source tree. * * @format + * @flow strict-local */ import NativeDevSettings from '../NativeModules/specs/NativeDevSettings'; import NativeEventEmitter from '../EventEmitter/NativeEventEmitter'; -class DevSettings extends NativeEventEmitter { +interface IDevSettings { + addMenuItem(title: string, handler: () => mixed): void; + reload(reason?: string): void; + onFastRefresh(): void; +} + +class DevSettings extends NativeEventEmitter implements IDevSettings { _menuItems: Map mixed>; constructor() { @@ -39,9 +46,9 @@ class DevSettings extends NativeEventEmitter { }); } - reload(reason: string) { + reload(reason?: string) { if (typeof NativeDevSettings.reloadWithReason === 'function') { - NativeDevSettings.reloadWithReason(reason || 'Uncategorized from JS'); + NativeDevSettings.reloadWithReason(reason ?? 'Uncategorized from JS'); } else { NativeDevSettings.reload(); } @@ -57,9 +64,12 @@ class DevSettings extends NativeEventEmitter { } // Avoid including the full `NativeDevSettings` class in prod. -class NoopDevSettings { +class NoopDevSettings implements IDevSettings { addMenuItem(title: string, handler: () => mixed) {} - reload() {} + reload(reason?: string) {} + onFastRefresh() {} } -module.exports = __DEV__ ? new DevSettings() : new NoopDevSettings(); +module.exports = ((__DEV__ + ? new DevSettings() + : new NoopDevSettings()): IDevSettings); diff --git a/Libraries/Utilities/GlobalPerformanceLogger.js b/Libraries/Utilities/GlobalPerformanceLogger.js index dedce0d110f..32ca41728bc 100644 --- a/Libraries/Utilities/GlobalPerformanceLogger.js +++ b/Libraries/Utilities/GlobalPerformanceLogger.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Utilities/HMRClient.js b/Libraries/Utilities/HMRClient.js index cf5d8eb54f6..7f00117793d 100644 --- a/Libraries/Utilities/HMRClient.js +++ b/Libraries/Utilities/HMRClient.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -271,7 +271,7 @@ function setHMRUnavailableReason(reason) { } function registerBundleEntryPoints(client) { - if (hmrUnavailableReason) { + if (hmrUnavailableReason != null) { DevSettings.reload('Bundle Splitting – Metro disconnected'); return; } diff --git a/Libraries/Utilities/NativeAppearance.js b/Libraries/Utilities/NativeAppearance.js index 5d37b8aded3..1f85cc30284 100644 --- a/Libraries/Utilities/NativeAppearance.js +++ b/Libraries/Utilities/NativeAppearance.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Utilities/NativeDevLoadingView.js b/Libraries/Utilities/NativeDevLoadingView.js index 8938fb6df5c..a122e2c487d 100644 --- a/Libraries/Utilities/NativeDevLoadingView.js +++ b/Libraries/Utilities/NativeDevLoadingView.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ diff --git a/Libraries/Utilities/NativeDevSplitBundleLoader.js b/Libraries/Utilities/NativeDevSplitBundleLoader.js index 505ae1c2108..987d47a5330 100644 --- a/Libraries/Utilities/NativeDevSplitBundleLoader.js +++ b/Libraries/Utilities/NativeDevSplitBundleLoader.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ diff --git a/Libraries/Utilities/NativeDeviceInfo.js b/Libraries/Utilities/NativeDeviceInfo.js index e1f2a6625de..840b754414c 100644 --- a/Libraries/Utilities/NativeDeviceInfo.js +++ b/Libraries/Utilities/NativeDeviceInfo.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Utilities/NativeJSDevSupport.js b/Libraries/Utilities/NativeJSDevSupport.js index 0c140f0f962..e609e1358ae 100644 --- a/Libraries/Utilities/NativeJSDevSupport.js +++ b/Libraries/Utilities/NativeJSDevSupport.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ diff --git a/Libraries/Utilities/NativePlatformConstantsAndroid.js b/Libraries/Utilities/NativePlatformConstantsAndroid.js index 39aa25d8c49..c12339267e5 100644 --- a/Libraries/Utilities/NativePlatformConstantsAndroid.js +++ b/Libraries/Utilities/NativePlatformConstantsAndroid.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Utilities/NativePlatformConstantsIOS.js b/Libraries/Utilities/NativePlatformConstantsIOS.js index fd73bcffadb..5b9d68bbc75 100644 --- a/Libraries/Utilities/NativePlatformConstantsIOS.js +++ b/Libraries/Utilities/NativePlatformConstantsIOS.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Utilities/Platform.android.js b/Libraries/Utilities/Platform.android.js index 3785bc8790a..ece5fe511ad 100644 --- a/Libraries/Utilities/Platform.android.js +++ b/Libraries/Utilities/Platform.android.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -22,9 +22,11 @@ export type PlatformSelectSpec = { const Platform = { __constants: null, OS: 'android', + // $FlowFixMe[unsafe-getters-setters] get Version(): number { return this.constants.Version; }, + // $FlowFixMe[unsafe-getters-setters] get constants(): {| isTesting: boolean, reactNativeVersion: {| @@ -46,12 +48,14 @@ const Platform = { } return this.__constants; }, + // $FlowFixMe[unsafe-getters-setters] get isTesting(): boolean { if (__DEV__) { return this.constants.isTesting; } return false; }, + // $FlowFixMe[unsafe-getters-setters] get isTV(): boolean { return this.constants.uiMode === 'tv'; }, diff --git a/Libraries/Utilities/Platform.ios.js b/Libraries/Utilities/Platform.ios.js index 2b8afec73e4..afb39c5aad8 100644 --- a/Libraries/Utilities/Platform.ios.js +++ b/Libraries/Utilities/Platform.ios.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -22,9 +22,11 @@ export type PlatformSelectSpec = { const Platform = { __constants: null, OS: 'ios', + // $FlowFixMe[unsafe-getters-setters] get Version(): string { return this.constants.osVersion; }, + // $FlowFixMe[unsafe-getters-setters] get constants(): {| forceTouchAvailable: boolean, interfaceIdiom: string, @@ -43,18 +45,22 @@ const Platform = { } return this.__constants; }, + // $FlowFixMe[unsafe-getters-setters] get isPad(): boolean { return this.constants.interfaceIdiom === 'pad'; }, /** * Deprecated, use `isTV` instead. */ + // $FlowFixMe[unsafe-getters-setters] get isTVOS(): boolean { return Platform.isTV; }, + // $FlowFixMe[unsafe-getters-setters] get isTV(): boolean { return this.constants.interfaceIdiom === 'tv'; }, + // $FlowFixMe[unsafe-getters-setters] get isTesting(): boolean { if (__DEV__) { return this.constants.isTesting; diff --git a/Libraries/Utilities/PolyfillFunctions.js b/Libraries/Utilities/PolyfillFunctions.js index dc6d5a0fbcc..9dd136f593f 100644 --- a/Libraries/Utilities/PolyfillFunctions.js +++ b/Libraries/Utilities/PolyfillFunctions.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ @@ -26,7 +26,7 @@ const defineLazyObjectProperty = require('./defineLazyObjectProperty'); * @see https://github.com/facebook/react-native/issues/934 */ function polyfillObjectProperty( - object: Object, + object: {...}, name: string, getValue: () => T, ): void { @@ -36,7 +36,7 @@ function polyfillObjectProperty( Object.defineProperty(object, backupName, descriptor); } - const {enumerable, writable, configurable} = descriptor || {}; + const {enumerable, writable, configurable = false} = descriptor || {}; if (descriptor && !configurable) { console.error('Failed to set polyfill. ' + name + ' is not configurable.'); return; diff --git a/Libraries/Utilities/RCTLog.js b/Libraries/Utilities/RCTLog.js index def04d6c3b2..78679c1f479 100644 --- a/Libraries/Utilities/RCTLog.js +++ b/Libraries/Utilities/RCTLog.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -20,11 +20,11 @@ const levelsMap = { fatal: 'error', }; -let warningHandler: ?(Array) => void = null; +let warningHandler: ?(...Array) => void = null; const RCTLog = { // level one of log, info, warn, error, mustfix - logIfNoNativeHook(level: string, ...args: Array): void { + logIfNoNativeHook(level: string, ...args: Array): void { // We already printed in the native console, so only log here if using a js debugger if (typeof global.nativeLoggingHook === 'undefined') { RCTLog.logToConsole(level, ...args); @@ -37,7 +37,7 @@ const RCTLog = { }, // Log to console regardless of nativeLoggingHook - logToConsole(level: string, ...args: Array): void { + logToConsole(level: string, ...args: Array): void { const logFn = levelsMap[level]; invariant( logFn, diff --git a/Libraries/Utilities/binaryToBase64.js b/Libraries/Utilities/binaryToBase64.js index 19d23d125d2..8ae743553b7 100644 --- a/Libraries/Utilities/binaryToBase64.js +++ b/Libraries/Utilities/binaryToBase64.js @@ -5,15 +5,16 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; const base64 = require('base64-js'); -function binaryToBase64(data: ArrayBuffer | $ArrayBufferView): any { +function binaryToBase64(data: ArrayBuffer | $ArrayBufferView): string { if (data instanceof ArrayBuffer) { + // $FlowFixMe[reassign-const] data = new Uint8Array(data); } if (data instanceof Uint8Array) { @@ -22,7 +23,8 @@ function binaryToBase64(data: ArrayBuffer | $ArrayBufferView): any { if (!ArrayBuffer.isView(data)) { throw new Error('data must be ArrayBuffer or typed array'); } - const {buffer, byteOffset, byteLength} = data; + // Already checked that `data` is `DataView` in `ArrayBuffer.isView(data)` + const {buffer, byteOffset, byteLength} = ((data: $FlowFixMe): DataView); return base64.fromByteArray(new Uint8Array(buffer, byteOffset, byteLength)); } diff --git a/Libraries/Utilities/codegenNativeComponent.js b/Libraries/Utilities/codegenNativeComponent.js index 809cdce1965..8376d9b4032 100644 --- a/Libraries/Utilities/codegenNativeComponent.js +++ b/Libraries/Utilities/codegenNativeComponent.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ // TODO: move this file to shims/ReactNative (requires React update and sync) @@ -31,7 +31,7 @@ function codegenNativeComponent( options?: Options, ): NativeComponentType { let componentNameInUse = - options && options.paperComponentName + options && options.paperComponentName != null ? options.paperComponentName : componentName; @@ -45,7 +45,7 @@ function codegenNativeComponent( componentNameInUse = options.paperComponentNameDeprecated; } else { throw new Error( - `Failed to find native component for either ${componentName} or ${options.paperComponentNameDeprecated || + `Failed to find native component for either ${componentName} or ${options.paperComponentNameDeprecated ?? '(unknown)'}`, ); } diff --git a/Libraries/Utilities/createPerformanceLogger.js b/Libraries/Utilities/createPerformanceLogger.js index 556363a5fa4..927cb54e8b3 100644 --- a/Libraries/Utilities/createPerformanceLogger.js +++ b/Libraries/Utilities/createPerformanceLogger.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict * @format */ @@ -35,9 +35,9 @@ export type IPerformanceLogger = { hasTimespan(string): boolean, logTimespans(): void, addTimespans(Array, Array): void, - setExtra(string, any): void, - getExtras(): {[key: string]: any, ...}, - removeExtra(string): ?any, + setExtra(string, mixed): void, + getExtras(): {[key: string]: mixed, ...}, + removeExtra(string): ?mixed, logExtras(): void, markPoint(string, number | void): void, getPoints(): {[key: string]: number, ...}, @@ -58,7 +58,7 @@ const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally function createPerformanceLogger(): IPerformanceLogger { const result: IPerformanceLogger & { _timespans: {[key: string]: Timespan, ...}, - _extras: {[key: string]: any, ...}, + _extras: {[key: string]: mixed, ...}, _points: {[key: string]: number, ...}, ... } = { @@ -206,7 +206,7 @@ function createPerformanceLogger(): IPerformanceLogger { } }, - setExtra(key: string, value: any) { + setExtra(key: string, value: mixed) { if (this._extras[key]) { if (PRINT_TO_CONSOLE && __DEV__) { infoLog( @@ -223,7 +223,7 @@ function createPerformanceLogger(): IPerformanceLogger { return this._extras; }, - removeExtra(key: string): ?any { + removeExtra(key: string): ?mixed { const value = this._extras[key]; delete this._extras[key]; return value; diff --git a/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js b/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js index 974314539d2..72ddbe5cdda 100644 --- a/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +++ b/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -27,7 +27,9 @@ * Freezing the object and adding the throw mechanism is expensive and will * only be used in DEV. */ -function deepFreezeAndThrowOnMutationInDev(object: T): T { +function deepFreezeAndThrowOnMutationInDev>( + object: T, +): T { if (__DEV__) { if ( typeof object !== 'object' || @@ -38,7 +40,8 @@ function deepFreezeAndThrowOnMutationInDev(object: T): T { return object; } - const keys = Object.keys(object); + // $FlowFixMe[not-an-object] `object` can be an array, but Object.keys works with arrays too + const keys = Object.keys((object: {...} | Array)); const hasOwnProperty = Object.prototype.hasOwnProperty; for (let i = 0; i < keys.length; i++) { diff --git a/Libraries/Utilities/defineLazyObjectProperty.js b/Libraries/Utilities/defineLazyObjectProperty.js index 9c5698a7036..c1b486a5fe4 100644 --- a/Libraries/Utilities/defineLazyObjectProperty.js +++ b/Libraries/Utilities/defineLazyObjectProperty.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; @@ -14,7 +14,7 @@ * Defines a lazily evaluated property on the supplied `object`. */ function defineLazyObjectProperty( - object: Object, + object: {...}, name: string, descriptor: { get: () => T, diff --git a/Libraries/Utilities/stringifySafe.js b/Libraries/Utilities/stringifySafe.js index effeedcd299..e051f59f8f0 100644 --- a/Libraries/Utilities/stringifySafe.js +++ b/Libraries/Utilities/stringifySafe.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Utilities/warnOnce.js b/Libraries/Utilities/warnOnce.js index 70c7460c785..adbc64ebc85 100644 --- a/Libraries/Utilities/warnOnce.js +++ b/Libraries/Utilities/warnOnce.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow strict-local + * @flow strict */ 'use strict'; diff --git a/Libraries/Vibration/NativeVibration.js b/Libraries/Vibration/NativeVibration.js index 6de5352ec82..d2b2f2424e9 100644 --- a/Libraries/Vibration/NativeVibration.js +++ b/Libraries/Vibration/NativeVibration.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict-local + * @flow strict * @format */ diff --git a/Libraries/Vibration/Vibration.js b/Libraries/Vibration/Vibration.js index 4a2d8444ea7..ab7f466be62 100644 --- a/Libraries/Vibration/Vibration.js +++ b/Libraries/Vibration/Vibration.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict * @jsdoc */ @@ -31,6 +31,7 @@ function vibrateByPattern(pattern: Array, repeat: boolean = false) { _vibrating = true; if (pattern[0] === 0) { NativeVibration.vibrate(_default_vibration_length); + // $FlowFixMe[reassign-const] pattern = pattern.slice(1); } if (pattern.length === 0) { @@ -52,6 +53,7 @@ function vibrateScheduler( NativeVibration.vibrate(_default_vibration_length); if (nextIndex >= pattern.length) { if (repeat) { + // $FlowFixMe[reassign-const] nextIndex = 0; } else { _vibrating = false; diff --git a/Libraries/promiseRejectionIsError.js b/Libraries/promiseRejectionIsError.js index f17583d7b0c..2df61813e7b 100644 --- a/Libraries/promiseRejectionIsError.js +++ b/Libraries/promiseRejectionIsError.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict */ 'use strict'; diff --git a/flow-typed/npm/base64-js_v1.x.x.js b/flow-typed/npm/base64-js_v1.x.x.js new file mode 100644 index 00000000000..8653866fdba --- /dev/null +++ b/flow-typed/npm/base64-js_v1.x.x.js @@ -0,0 +1,14 @@ +/** + * (c) Facebook, Inc. and its affiliates. Confidential and proprietary. + * + * @flow strict + * @format + */ + +declare module 'base64-js' { + declare module.exports: { + byteLength: string => number, + fromByteArray: (Uint8Array | Array) => string, + toByteArray: string => Uint8Array, + }; +} diff --git a/flow-typed/npm/pretty-format_v26.x.x.js b/flow-typed/npm/pretty-format_v26.x.x.js new file mode 100644 index 00000000000..181d7909b34 --- /dev/null +++ b/flow-typed/npm/pretty-format_v26.x.x.js @@ -0,0 +1,51 @@ +/** + * (c) Facebook, Inc. and its affiliates. Confidential and proprietary. + * + * @flow strict + * @format + */ + +type PrettyFormatPlugin = + | { + test: (value: mixed) => boolean, + print: (value: mixed) => string, + } + | { + test: (value: mixed) => boolean, + serialize: (value: mixed) => string, + }; + +declare module 'pretty-format' { + declare module.exports: { + ( + value: mixed, + options?: ?{ + callToJSON?: ?boolean, + escapeRegex?: ?boolean, + escapeString?: ?boolean, + highlight?: ?boolean, + indent?: ?number, + maxDepth?: ?number, + min?: ?boolean, + plugins?: ?Array, + printFunctionName?: ?boolean, + theme?: ?{ + comment?: ?string, + prop?: ?string, + tag?: ?string, + value: ?string, + }, + }, + ): string, + + plugins: { + AsymmetricMatcher: PrettyFormatPlugin, + ConvertAnsi: PrettyFormatPlugin, + DOMCollection: PrettyFormatPlugin, + DOMElement: PrettyFormatPlugin, + Immutable: PrettyFormatPlugin, + ReactElement: PrettyFormatPlugin, + ReactTestComponent: PrettyFormatPlugin, + }, + }; +} diff --git a/flow-typed/npm/promise_v8.x.x.js b/flow-typed/npm/promise_v8.x.x.js new file mode 100644 index 00000000000..580f98cdd63 --- /dev/null +++ b/flow-typed/npm/promise_v8.x.x.js @@ -0,0 +1,32 @@ +/** + * (c) Facebook, Inc. and its affiliates. Confidential and proprietary. + * + * @flow strict + * @format + */ + +declare module 'promise/setimmediate/es6-extensions' { + declare module.exports: Class; +} + +declare module 'promise/setimmediate/done' { + declare module.exports: Class; +} + +declare module 'promise/setimmediate/finally' { + declare module.exports: Class; +} + +declare module 'promise/setimmediate/rejection-tracking' { + declare module.exports: { + enable: ( + options?: ?{ + whitelist?: ?Array, + allRejections?: ?boolean, + onUnhandled?: ?(number, mixed) => void, + onHandled?: ?(number, mixed) => void, + }, + ) => void, + disable: () => void, + }; +} diff --git a/flow-typed/npm/stacktrace-parser_v0.1.x.js b/flow-typed/npm/stacktrace-parser_v0.1.x.js new file mode 100644 index 00000000000..9e990144531 --- /dev/null +++ b/flow-typed/npm/stacktrace-parser_v0.1.x.js @@ -0,0 +1,19 @@ +/** + * (c) Facebook, Inc. and its affiliates. Confidential and proprietary. + * + * @flow strict + * @format + */ + +type StackFrame = { + file: string, + methodName: string, + lineNumber: number, + column: ?number, +}; + +declare module 'stacktrace-parser' { + declare module.exports: { + parse: string => Array, + }; +} diff --git a/scripts/versiontemplates/ReactNativeVersion.js.template b/scripts/versiontemplates/ReactNativeVersion.js.template index 9e05c12fd81..72bfcfef110 100644 --- a/scripts/versiontemplates/ReactNativeVersion.js.template +++ b/scripts/versiontemplates/ReactNativeVersion.js.template @@ -6,7 +6,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow + * @flow strict */ exports.version = {