microsoft / microsoft/TypeScript

Unreachable code defaults

Open
#25,738 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Docs
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Apparently, since 2.9.1, unreachable code is allowed by default, you have to explicitly set allowUnreachableCode to false in tsconfig.json to get the old behavior.

This doesn't match what's described in the docs.

image

Quick repro :
package.json

{
  "name": "tmp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "typescript": "2.9.1"
  }
}

tsconfig.json (default from tsc --init)

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true
  }
}

index.ts

export const a = (): boolean => {
    return true;
    return false;
};

yarn tsc outputs no warning as of 2.9.1

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 compiler-options documentation linked in the issue and reproduce the behavior using the shown tsconfig.json and index.ts under TypeScript 2.9.1. Compare the documented default for allowUnreachableCode with the compiler's actual behavior and determine whether the documentation or compiler should change. Done means the default behavior and documentation agree, with the reproduction covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.