microsoft / microsoft/TypeScript
Generalize `never` type handling for control flow analysis based type guard
Open
Nobody has claimed this yet.
In Discussion
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
I guess there would be some duplicates, but I cannot find it.
TypeScript Version: 2.1.14
Code
function throwError(): never {
throw new Error();
}
let foo: string | undefined;
if (!foo) {
throwError();
}
foo; // Expected to be `string` instead of `string | undefined`.
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 example in the issue and verify how control-flow analysis treats a call to a function returning never. Trace the type-guard narrowing for foo after throwError(); done means foo is inferred as string rather than string | undefined while preserving the existing never behavior.
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
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100