diff --git a/packages/react-native/Libraries/EventEmitter/RCTEventEmitter.js b/packages/react-native/Libraries/EventEmitter/RCTEventEmitter.js index 069caedcb25..3e5bb8e6624 100644 --- a/packages/react-native/Libraries/EventEmitter/RCTEventEmitter.js +++ b/packages/react-native/Libraries/EventEmitter/RCTEventEmitter.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 */ @@ -12,8 +12,22 @@ import registerCallableModule from '../Core/registerCallableModule'; +type EventEmitterModule = { + receiveEvent: ( + rootNodeID: number, + topLevelType: string, + nativeEventParam: unknown, + ) => void, + receiveTouches: ( + eventTopLevelType: string, + touches: Array, + changedIndices: Array, + ) => void, + ... +}; + const RCTEventEmitter = { - register(eventEmitter: any) { + register(eventEmitter: EventEmitterModule) { registerCallableModule('RCTEventEmitter', eventEmitter); }, }; diff --git a/packages/react-native/Libraries/Interaction/PanResponder.js b/packages/react-native/Libraries/Interaction/PanResponder.js index 3c31c1a895c..fbf0a5d5f0b 100644 --- a/packages/react-native/Libraries/Interaction/PanResponder.js +++ b/packages/react-native/Libraries/Interaction/PanResponder.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/packages/react-native/Libraries/Lists/__flowtests__/SectionList-flowtest.js b/packages/react-native/Libraries/Lists/__flowtests__/SectionList-flowtest.js index 9f5a7efd200..769e0da3237 100644 --- a/packages/react-native/Libraries/Lists/__flowtests__/SectionList-flowtest.js +++ b/packages/react-native/Libraries/Lists/__flowtests__/SectionList-flowtest.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 */ @@ -22,7 +22,7 @@ function renderMyListItem(info: { const renderMyHeader = ({ section, }: { - section: {fooNumber: number, ...} & Object, + section: {fooNumber: number, ...}, ... }) => ; diff --git a/packages/react-native/Libraries/WebSocket/WebSocket.js b/packages/react-native/Libraries/WebSocket/WebSocket.js index 9c08c3bdd0b..2eccf431b19 100644 --- a/packages/react-native/Libraries/WebSocket/WebSocket.js +++ b/packages/react-native/Libraries/WebSocket/WebSocket.js @@ -4,10 +4,12 @@ * 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 */ +// flowlint unsafe-getters-setters:off + import type {EventCallback} from '../../src/private/webapis/dom/events/EventTarget'; import type {BlobData} from '../Blob/BlobTypes'; import type {EventSubscription} from '../vendor/emitter/EventEmitter'; @@ -98,29 +100,29 @@ class WebSocket extends EventTarget { constructor( url: string, protocols: ?string | ?Array, - options: ?{headers?: {origin?: string, ...}, ...}, + options: ?{headers?: {origin?: string, ...}, origin?: string, ...}, ) { super(); this.url = url; - if (typeof protocols === 'string') { - protocols = [protocols]; - } + const protocolList: ?Array = + typeof protocols === 'string' + ? [protocols] + : Array.isArray(protocols) + ? protocols + : null; - const {headers = {}, ...unrecognized} = options || {}; + const {headers = {}, ...unrecognized} = (options ?? {}) as { + headers?: {origin?: string, ...}, + origin?: string, + ... + }; // Preserve deprecated backwards compatibility for the 'origin' option - // $FlowFixMe[prop-missing] if (unrecognized && typeof unrecognized.origin === 'string') { console.warn( 'Specifying `origin` as a WebSocket connection option is deprecated. Include it under `headers` instead.', ); - /* $FlowFixMe[prop-missing] (>=0.54.0 site=react_native_fb,react_native_ - * oss) This comment suppresses an error found when Flow v0.54 was - * deployed. To see the error delete this comment and run Flow. */ headers.origin = unrecognized.origin; - /* $FlowFixMe[prop-missing] (>=0.54.0 site=react_native_fb,react_native_ - * oss) This comment suppresses an error found when Flow v0.54 was - * deployed. To see the error delete this comment and run Flow. */ delete unrecognized.origin; } @@ -134,10 +136,6 @@ class WebSocket extends EventTarget { ); } - if (!Array.isArray(protocols)) { - protocols = null; - } - this._eventEmitter = new NativeEventEmitter( // T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior // If you want to use the native module on other platforms, please remove this condition and test its behavior @@ -149,7 +147,7 @@ class WebSocket extends EventTarget { global.__NETWORK_REPORTER__?.createDevToolsRequestId(); NativeWebSocketModule.connect( url, - protocols, + protocolList, {headers, unstable_devToolsRequestId: devToolsRequestId}, this._socketId, ); diff --git a/packages/react-native/Libraries/__flowtests__/ReactNativeTypes-flowtest.js b/packages/react-native/Libraries/__flowtests__/ReactNativeTypes-flowtest.js index 57c5c891073..38c0a45aac4 100644 --- a/packages/react-native/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +++ b/packages/react-native/Libraries/__flowtests__/ReactNativeTypes-flowtest.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 */ @@ -15,7 +15,7 @@ import * as React from 'react'; function takesHostComponentInstance(instance: HostInstance | null): void {} -const MyHostComponent = 'Host' as any as HostComponent<{...}>; +declare const MyHostComponent: HostComponent<{...}>; {