From 6097276347afe0bd989033f7e5ff78efe66ec2e8 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Sat, 21 Nov 2026 13:16:10 -0800 Subject: [PATCH] Fix Flow types that use `void` for a missing value (#2265) Summary: X-link: https://github.com/react/react-native/pull/60206 Under Flow's `experimental.ts_void`, `void` is TypeScript's `void`, which flows only into `void`, `any` and `unknown`, so a value typed `void` can't be passed where an optional value or `undefined` is expected. This updates React Native's Flow types for projects that check React Native's sources with that option: - Library definitions say `undefined` where the TypeScript definitions do: `babel/traverse`'s `Scope#getBinding()`, `Scope#getOwnBinding()`, `Scope#getBindingIdentifier()` and `Scope#getOwnBindingIdentifier()`, and `child_process.spawnSync()`'s `error`. execa's `env` is read-only, so it accepts both `process.env` and objects with `void` values. - `BackHandler` handlers and the RN tester's stall handler may return nothing. - `EventTarget`'s listener maps and codegen's `bubblingType` use maybe types instead of `void`, `componentDidMount()` in `TouchableNativeFeedback` returns `void`, and two RN tester components that render nothing return `undefined`. - Where the only fix needs the `undefined` type, which this repository's Flow config doesn't enable, the error is suppressed. Without that option, `void` and `undefined` are the same type, so nothing changes. Changelog: [General][Changed] - Allow `BackHandler` event listeners to return nothing [General][Changed] - Type `TouchableNativeFeedback`'s `componentDidMount()` as returning `void` Reviewed By: christophpurrer Differential Revision: D133660807 --- flow-typed/environment/node.js | 2 +- flow-typed/npm/babel-traverse_v7.x.x.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flow-typed/environment/node.js b/flow-typed/environment/node.js index 295853ae60..6351206249 100644 --- a/flow-typed/environment/node.js +++ b/flow-typed/environment/node.js @@ -426,7 +426,7 @@ type child_process$spawnSyncRet = Readonly<{ // TODO: subprocess.status may be null in case of error or signal status: number, signal: string | null, - error: Error | void, + error: Error | undefined, }>; type child_process$spawnSyncOpts = Readonly<{ diff --git a/flow-typed/npm/babel-traverse_v7.x.x.js b/flow-typed/npm/babel-traverse_v7.x.x.js index c5988473f3..3434fd6db7 100644 --- a/flow-typed/npm/babel-traverse_v7.x.x.js +++ b/flow-typed/npm/babel-traverse_v7.x.x.js @@ -533,13 +533,13 @@ declare module '@babel/traverse' { bindingIdentifierEquals(name: string, node: BabelNode): boolean; - getBinding(name: string): Binding | void; + getBinding(name: string): Binding | undefined; - getOwnBinding(name: string): Binding | void; + getOwnBinding(name: string): Binding | undefined; - getBindingIdentifier(name: string): BabelNodeIdentifier | void; + getBindingIdentifier(name: string): BabelNodeIdentifier | undefined; - getOwnBindingIdentifier(name: string): BabelNodeIdentifier | void; + getOwnBindingIdentifier(name: string): BabelNodeIdentifier | undefined; hasOwnBinding(name: string): boolean;