Skip to content

Fix Flow types that use void for a missing value - #2265

Open
SamChou19815 wants to merge 1 commit into
mainfrom
export-D133660807
Open

SamChou19815 wants to merge 1 commit into
mainfrom
export-D133660807

Conversation

@SamChou19815

Copy link
Copy Markdown
Member

Summary:
X-link: react/react-native#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() 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

Differential Revision: D133660807

Summary:
X-link: react/react-native#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()` 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`

Differential Revision: D133660807
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 21, 2026
@meta-codesync

meta-codesync Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@SamChou19815 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133660807.

@github-actions

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: 575d1d5 · 3 commands run

This PR changes two Flow libdef annotations from void to undefined: Scope#getBinding() in @babel/traverse and child_process.spawnSync()'s error. The new types match the TypeScript definitions. Under Metro's current Flow config (0.341, no ts_void), Flow treats undefined in a libdef as void. The repo typechecks cleanly and callers still see Binding | void, so the change is type-only with no runtime effect. I found no problems.

No findings.

Verified
  • ✅ yarn typecheck — No errors at the PR head with Flow 0.341.0.
  • ✅ printf <probe using Scope#getBinding and undefined annotations> | yarn flow check-contents packages/metro/src/index.js — getBinding() in the libdef resolves to Binding | void (an assignment to number reports both Binding and void as incompatible). In user code, undefined as a type still raises unsupported-syntax, so the libdef use doesn't leak that error to callers.
  • ✅ yarn eslint flow-typed/environment/node.js flow-typed/npm/babel-traverse_v7.x.x.js — Both files are excluded by ESLint's ignore patterns.

Not run: I ran no tests or benchmarks. The change touches only Flow libdef annotations, which have no runtime effect or performance cost. I didn't check behavior under Flow's experimental.ts_void option, because Metro's .flowconfig doesn't enable it.

Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. needs-meta-import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant