microsoft / microsoft/TypeScript
Return type inference error with async functions and Promise.reject()
Open
Nobody has claimed this yet.
Bug
Domain: check: Type Inference
Needs Human Review
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.0.1
Code
async function often() {
if (false) {
return Promise.reject();
}
// code
}
let sometimes = often();
sometimes = Promise.resolve();
Actual behavior:
error TS2322: Type 'Promise<void>' is not assignable to type 'Promise<never>'.
Playground Link: here
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript Playground link and the async function/Promise.reject repro, then trace the inferred type reported by the assignment to sometimes. Add focused coverage for this example and verify that the valid Promise.resolve assignment no longer produces TS2322 while the rejection path remains correctly typed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100