diff --git a/IntegrationTests/TimersTest.js b/IntegrationTests/TimersTest.js index 04496e0a943..3a74f97edf3 100644 --- a/IntegrationTests/TimersTest.js +++ b/IntegrationTests/TimersTest.js @@ -39,7 +39,7 @@ class TimersTest extends React.Component { }; setTimeout(fn: () => void, time: number): TimeoutID { - const id = setTimeout(() => { + const id: TimeoutID = setTimeout(() => { this._timeoutIDs.delete(id); fn(); }, time); @@ -70,7 +70,7 @@ class TimersTest extends React.Component { } setImmediate(fn: () => void): ImmediateID { - const id = setImmediate(() => { + const id: any = setImmediate(() => { this._immediateIDs.delete(id); fn(); }); @@ -81,7 +81,7 @@ class TimersTest extends React.Component { } requestAnimationFrame(fn: () => void): AnimationFrameID { - const id = requestAnimationFrame(() => { + const id: AnimationFrameID = requestAnimationFrame(() => { this._animationFrameIDs.delete(id); fn(); }); diff --git a/Libraries/Animated/AnimatedImplementation.js b/Libraries/Animated/AnimatedImplementation.js index 21f6c7069e1..7e25c65f2a4 100644 --- a/Libraries/Animated/AnimatedImplementation.js +++ b/Libraries/Animated/AnimatedImplementation.js @@ -415,7 +415,7 @@ const parallel = function ( }); }, - _startNativeLoop: function () { + _startNativeLoop: function (): empty { throw new Error( 'Loops run using the native driver cannot contain Animated.parallel animations', ); diff --git a/Libraries/BatchedBridge/MessageQueue.js b/Libraries/BatchedBridge/MessageQueue.js index 65c7102ca72..a9810bc6f94 100644 --- a/Libraries/BatchedBridge/MessageQueue.js +++ b/Libraries/BatchedBridge/MessageQueue.js @@ -252,7 +252,7 @@ class MessageQueue { // folly-convertible. As a special case, if a prop value is a // function it is permitted here, and special-cased in the // conversion. - const isValidArgument = (val: mixed) => { + const isValidArgument = (val: mixed): boolean => { switch (typeof val) { case 'undefined': case 'boolean': diff --git a/Libraries/BugReporting/getReactData.js b/Libraries/BugReporting/getReactData.js index 4440cc4e0d0..cc988ced109 100644 --- a/Libraries/BugReporting/getReactData.js +++ b/Libraries/BugReporting/getReactData.js @@ -165,7 +165,7 @@ function copyWithSetImpl( path: Array, idx: number, value: any, -) { +): any { if (idx >= path.length) { return value; } diff --git a/Libraries/Core/Timers/JSTimers.js b/Libraries/Core/Timers/JSTimers.js index 8147ebb8e90..33f8a68d76b 100644 --- a/Libraries/Core/Timers/JSTimers.js +++ b/Libraries/Core/Timers/JSTimers.js @@ -242,7 +242,7 @@ const JSTimers = { * @param {function} func Callback to be invoked before the end of the * current JavaScript execution loop. */ - queueReactNativeMicrotask: function (func: Function, ...args: any) { + queueReactNativeMicrotask: function (func: Function, ...args: any): number { const id = _allocateCallback( () => func.apply(undefined, args), 'queueReactNativeMicrotask', @@ -254,7 +254,7 @@ const JSTimers = { /** * @param {function} func Callback to be invoked every frame. */ - requestAnimationFrame: function (func: Function) { + requestAnimationFrame: function (func: Function): any | number { const id = _allocateCallback(func, 'requestAnimationFrame'); createTimer(id, 1, Date.now(), /* recurring */ false); return id; @@ -265,16 +265,19 @@ const JSTimers = { * with time remaining in frame. * @param {?object} options */ - requestIdleCallback: function (func: Function, options: ?Object) { + requestIdleCallback: function ( + func: Function, + options: ?Object, + ): any | number { if (requestIdleCallbacks.length === 0) { setSendIdleEvents(true); } const timeout = options && options.timeout; - const id = _allocateCallback( + const id: number = _allocateCallback( timeout != null ? (deadline: any) => { - const timeoutId = requestIdleCallbackTimeouts[id]; + const timeoutId: number = requestIdleCallbackTimeouts[id]; if (timeoutId) { JSTimers.clearTimeout(timeoutId); delete requestIdleCallbackTimeouts[id]; @@ -287,8 +290,8 @@ const JSTimers = { requestIdleCallbacks.push(id); if (timeout != null) { - const timeoutId = JSTimers.setTimeout(() => { - const index = requestIdleCallbacks.indexOf(id); + const timeoutId: number = JSTimers.setTimeout(() => { + const index: number = requestIdleCallbacks.indexOf(id); if (index > -1) { requestIdleCallbacks.splice(index, 1); _callTimer(id, global.performance.now(), true); @@ -345,7 +348,7 @@ const JSTimers = { * This is called from the native side. We are passed an array of timerIDs, * and */ - callTimers: function (timersToCall: Array) { + callTimers: function (timersToCall: Array): any | void { invariant( timersToCall.length !== 0, 'Cannot call `callTimers` with an empty list of IDs.', diff --git a/Libraries/Lists/ViewabilityHelper.js b/Libraries/Lists/ViewabilityHelper.js index 104f3931c0a..33a9811825a 100644 --- a/Libraries/Lists/ViewabilityHelper.js +++ b/Libraries/Lists/ViewabilityHelper.js @@ -234,7 +234,7 @@ class ViewabilityHelper { } this._viewableIndices = viewableIndices; if (this._config.minimumViewTime) { - const handle = setTimeout(() => { + const handle: TimeoutID = setTimeout(() => { /* $FlowFixMe[incompatible-call] (>=0.63.0 site=react_native_fb) This * comment suppresses an error found when Flow v0.63 was deployed. To * see the error delete this comment and run Flow. */ diff --git a/Libraries/LogBox/Data/LogBoxData.js b/Libraries/LogBox/Data/LogBoxData.js index d868d89e8e9..6c5e160dfe0 100644 --- a/Libraries/LogBox/Data/LogBoxData.js +++ b/Libraries/LogBox/Data/LogBoxData.js @@ -68,7 +68,7 @@ const observers: Set<{observer: Observer, ...}> = new Set(); const ignorePatterns: Set = new Set(); let appInfo: ?() => AppInfo = null; let logs: LogBoxLogs = new Set(); -let updateTimeout = null; +let updateTimeout: $FlowFixMe | null = null; let _isDisabled = false; let _selectedIndex = -1; diff --git a/Libraries/vendor/emitter/__tests__/EventEmitter-test.js b/Libraries/vendor/emitter/__tests__/EventEmitter-test.js index 7ae26000cc6..99288ac3e2e 100644 --- a/Libraries/vendor/emitter/__tests__/EventEmitter-test.js +++ b/Libraries/vendor/emitter/__tests__/EventEmitter-test.js @@ -9,6 +9,8 @@ * @oncall react_native */ +import type {EventSubscription} from '../EventEmitter'; + import EventEmitter from '../EventEmitter'; describe('listeners', () => { @@ -309,7 +311,7 @@ describe('event emission', () => { const listenerA = jest.fn(() => { results.push('A'); }); - const listenerB = jest.fn(() => { + const listenerB: JestMockFn, void> = jest.fn(() => { results.push('B'); subscriptionB.remove(); }); @@ -317,7 +319,10 @@ describe('event emission', () => { results.push('C'); }); emitter.addListener('A', listenerA); - const subscriptionB = emitter.addListener('A', listenerB); + const subscriptionB: EventSubscription = emitter.addListener( + 'A', + listenerB, + ); emitter.addListener('A', listenerC); emitter.emit('A'); diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js index ea84c731b2c..d0864ca5ea8 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js @@ -295,7 +295,7 @@ function getParamObjCType( function getReturnObjCType( methodName: string, nullableTypeAnnotation: Nullable, -) { +): string { const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); function wrapIntoNullableIfNeeded(generatedType: string) { diff --git a/packages/react-native-codegen/src/parsers/flow/components/events.js b/packages/react-native-codegen/src/parsers/flow/components/events.js index a6a788a467d..8384edd789b 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/events.js +++ b/packages/react-native-codegen/src/parsers/flow/components/events.js @@ -104,7 +104,11 @@ function findEventArgumentsAndType( types: TypeMap, bubblingType: void | 'direct' | 'bubble', paperName: ?$FlowFixMe, -) { +): { + argumentProps: $FlowFixMe, + bubblingType: ?('direct' | 'bubble'), + paperTopLevelNameDeprecated: ?$FlowFixMe, +} { if (!typeAnnotation.id) { throw new Error("typeAnnotation of event doesn't have a name"); } diff --git a/packages/rn-tester/js/examples/ActivityIndicator/ActivityIndicatorExample.js b/packages/rn-tester/js/examples/ActivityIndicator/ActivityIndicatorExample.js index 7be8bc4a5dd..2713fce143f 100644 --- a/packages/rn-tester/js/examples/ActivityIndicator/ActivityIndicatorExample.js +++ b/packages/rn-tester/js/examples/ActivityIndicator/ActivityIndicatorExample.js @@ -17,7 +17,7 @@ function ToggleAnimatingActivityIndicator() { const [animating, setAnimating] = useState(true); - const setToggleTimeout = useCallback(() => { + const setToggleTimeout: () => void = useCallback(() => { timer.current = setTimeout(() => { setAnimating(currentState => !currentState); setToggleTimeout(); diff --git a/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExTilt.js b/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExTilt.js index 3f9552ca88d..3e9b54a338d 100644 --- a/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExTilt.js +++ b/packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExTilt.js @@ -60,7 +60,7 @@ class AnExTilt extends React.Component { useNativeDriver: false, }).start(); this.state.panX.removeAllListeners(); - const id = this.state.panX.addListener(({value}) => { + const id: any = this.state.panX.addListener(({value}) => { // listen until offscreen if (Math.abs(value) > 400) { this.state.panX.removeListener(id); // offscreen, so stop listening