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__ ```
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 that a function without an explicit return typeannotation returns
void. That isn't true ofasyncfunctions, which alwaysreturn a
Promise, so our generated.d.tsdeclares seven async functions asreturning
void- including the publicServer#end(),Watcher#watch(),Watcher#close()andDependencyGraph#end(). TypeScript consumers awaitingthose get
await-thenablefrom typescript-eslint, or quietly don't await atall.
I've fixed the translator upstream in
facebook/flow#9486, but 0.84.x pins
flow-api-translator0.35.0 and I'd rather not bump the toolchain on a releasebranch, 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 wewant in the source regardless.
mainwill pick the translator fix up with thenext 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:
Test plan: