Skip to content

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

Closed
robhogan wants to merge 1 commit into
pr1895from
pr1896
Closed

[0.84] Types: Annotate Promise<void> returns on async functions#1896
robhogan wants to merge 1 commit into
pr1895from
pr1896

Conversation

@robhogan

@robhogan robhogan commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

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__

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 Sep 2, 2026
@robhogan robhogan closed this Sep 2, 2026
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