Skip to content

[0.85] Types: Annotate Promise<void> returns on async functions - #1913

Merged
robhogan merged 1 commit into
0.85.xfrom
0.05/annotate-promise-void-returns
Sep 7, 2026
Merged

[0.85] Types: Annotate Promise<void> returns on async functions#1913
robhogan merged 1 commit into
0.85.xfrom
0.05/annotate-promise-void-returns

Conversation

@robhogan

@robhogan robhogan commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Picks #1896 to 0.85.x

Changelog:

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

@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 Sep 7, 2026
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.85.x pins
`flow-api-translator` 0.36.1 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
robhogan force-pushed the 0.05/annotate-promise-void-returns branch from 05369d1 to da2db3c Compare September 7, 2026 15:30
@robhogan
robhogan merged commit 61e8966 into 0.85.x Sep 7, 2026
13 checks passed
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