[0.84] Types: Annotate Promise<void> returns on async functions - #1887
Merged
Conversation
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__ ```
robhogan
marked this pull request as ready for review
August 30, 2026 16:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
flow-api-translatorassumes a function without an explicit return typeannotation returns
void, which isn't true ofasyncfunctions. Seven of oursare declared
voidin the generated.d.ts, including the publicServer#end(),Watcher#watch()/#close()andDependencyGraph#end()- soTypeScript consumers awaiting those hit
await-thenable, or quietly don't awaitat 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
mainwill pick the translator fixup 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:
Test plan: