Skip to content

Type jest test and hook callbacks as @types/jest does - #60192

Merged
meta-codesync[bot] merged 1 commit into
mainfrom
export-D133411234
Nov 20, 2026
Merged

meta-codesync[bot] merged 1 commit into
mainfrom
export-D133411234

Conversation

@SamChou19815

Copy link
Copy Markdown
Member

Summary:
The jest callbacks were typed (done) => ?Promise<unknown>. With Flow's experimental.ts_void, a callback that returns void, such as afterEach(() => cleanup()), no longer fits that type. The callbacks are now typed as in TypeScript's types/jest:

  • tests: ProvidesCallback, i.e. ((done) => void) | (() => PromiseLike<unknown>);
  • hooks: ProvidesHookCallback, i.e. (() => any) | ProvidesCallback;
  • each callbacks: (...args) => any.

The done parameter of the afterEach callback in dev-middleware's ServerUtils test is now annotated. Flow 0.340 can't infer its type from the union.

Changelog: [Internal]

Differential Revision: D133411234

Summary:
The jest callbacks were typed `(done) => ?Promise<unknown>`. With Flow's `experimental.ts_void`, a callback that returns `void`, such as `afterEach(() => cleanup())`, no longer fits that type. The callbacks are now typed as in TypeScript's `types/jest`:
- tests: `ProvidesCallback`, i.e. `((done) => void) | (() => PromiseLike<unknown>)`;
- hooks: `ProvidesHookCallback`, i.e. `(() => any) | ProvidesCallback`;
- `each` callbacks: `(...args) => any`.

The `done` parameter of the `afterEach` callback in `dev-middleware`'s `ServerUtils` test is now annotated. Flow 0.340 can't infer its type from the union.

Changelog: [Internal]

Differential Revision: D133411234
@meta-codesync

meta-codesync Bot commented Nov 20, 2026

Copy link
Copy Markdown

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

@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 20, 2026
@meta-codesync
meta-codesync Bot merged commit 9075c45 into main Nov 20, 2026
88 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @SamChou19815 in 9075c45

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Nov 20, 2026
@SamChou19815
SamChou19815 deleted the export-D133411234 branch November 21, 2026 00:00
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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants