Skip to content

[0.84] Types: Annotate Promise<void> returns on async functions - #1887

Merged
robhogan merged 1 commit into
0.84.xfrom
robhogan/0.84/async-return-types
Aug 30, 2026
Merged

[0.84] Types: Annotate Promise<void> returns on async functions#1887
robhogan merged 1 commit into
0.84.xfrom
robhogan/0.84/async-return-types

Conversation

@robhogan

@robhogan robhogan commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

Summary:
flow-api-translator assumes a function without an explicit return type
annotation returns void, which isn't true of async functions. Seven of ours
are declared void in the generated .d.ts, including the public
Server#end(), Watcher#watch()/#close() and DependencyGraph#end() - so
TypeScript consumers awaiting those hit await-thenable, or quietly don't await
at all.

I've fixed the translator upstream in
facebook/flow#9486, but 0.84.x pins 0.35.0 and I'd
rather not bump the toolchain on a release branch, so this annotates the return
types at source. It's a no-op for Flow, and main will pick the translator fix
up with the next version bump. Translating every file the generator covers with
0.35.0 patched and unpatched confirms these seven, across five files, are the
complete set on this branch.

Changelog:

 - **[Types]**: async methods including `Server#end`, `Watcher#watch`/`#close` and `DependencyGraph#end` are declared as returning `Promise<void>` rather than `void`

Test plan:

yarn run build-ts-defs   # updates exactly the five .d.ts files, no other churn
yarn typecheck           # No errors!
yarn typecheck-ts
yarn jest packages/metro/src/Server/__tests__/Server-test.js packages/metro-file-map/src/__tests__ packages/metro-file-map/src/watchers/__tests__

Summary:
`flow-api-translator` assumes that a function without an explicit return type
annotation returns `void`. That isn't true of `async` functions, which always
return a `Promise`, so our generated `.d.ts` declares seven async functions as
returning `void` - including the public `Server#end()`, `Watcher#watch()`,
`Watcher#close()` and `DependencyGraph#end()`. TypeScript consumers awaiting
those get `await-thenable` from typescript-eslint, or quietly don't await at
all.

I've fixed the translator upstream in
facebook/flow#9486, but 0.84.x pins
`flow-api-translator` 0.35.0 and I'd rather not bump the toolchain on a release
branch, so this annotates the return types at source instead. It's a no-op for
Flow, which already infers `Promise<void>` in every case here, and it's what we
want in the source regardless. `main` will pick the translator fix up with the
next version bump, after which these annotations are still correct, just no
longer load-bearing.

To find the full set I translated every file the generator covers with 0.35.0
patched and unpatched and diffed the output - these seven declarations, across
five files, are all of them on this branch.

Changelog:
```
 - **[Fix]**: Types: async methods including `Server#end`, `Watcher#watch`/`#close` and `DependencyGraph#end` are declared as returning `Promise<void>` rather than `void`
```

Test plan:
```
yarn run build-ts-defs   # updates exactly the five .d.ts files, no other churn
yarn typecheck           # No errors!
yarn typecheck-ts
yarn jest packages/metro/src/Server/__tests__/Server-test.js packages/metro-file-map/src/__tests__ packages/metro-file-map/src/watchers/__tests__
```
@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 Aug 30, 2026
@robhogan
robhogan marked this pull request as ready for review August 30, 2026 16:52
@robhogan
robhogan merged commit 4147ac6 into 0.84.x Aug 30, 2026
16 checks passed
@robhogan
robhogan deleted the robhogan/0.84/async-return-types branch August 30, 2026 16:53
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant