microsoft / microsoft/TypeScript

Generalize `never` type handling for control flow analysis based type guard

Open
#12,825 11 comments 40 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.