Make assorted Libraries modules Flow strict-local (#57733)

Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57733

Upgrade several remaining Libraries modules (WebSocket, PanResponder, RCTEventEmitter, and Flow type tests) from `flow` to `flow strict-local` with accurate types. WebSocket exposes spec-mandated getters/setters and opts out of the `unsafe-getters-setters` lint with a scoped directive. Behavior is unchanged.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D113763779

fbshipit-source-id: 86827a975e996a4c85dd92344d36746e61887dde
This commit is contained in:
Rubén Norte authored and meta-codesync[bot] committed 2026-09-04 06:40:51 -07:00
1 parent a9dc32ce58
commit 50a7d464fb
5 files changed
+37 -25

No files matched your search

@@ -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<unknown>,
changedIndices: Array<number>,
) => void,
...
};
const RCTEventEmitter = {
register(eventEmitter: any) {
register(eventEmitter: EventEmitterModule) {
registerCallableModule('RCTEventEmitter', eventEmitter);
},
};
@@ -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
*/
@@ -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, ...},
...
}) => <span />;
+16 -18
View File
@@ -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<string>,
options: ?{headers?: {origin?: string, ...}, ...},
options: ?{headers?: {origin?: string, ...}, origin?: string, ...},
) {
super();
this.url = url;
if (typeof protocols === 'string') {
protocols = [protocols];
}
const protocolList: ?Array<string> =
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,
);
@@ -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<{...}>;
<MyHostComponent
ref={hostComponentRef => {