Skip to content

unreachable code detected not work for if clause. #39386

@ShuiRuTian

Description

@ShuiRuTian

TypeScript Version: 3.9.2

Search Terms: unreachable

Code

const hel2 = (x: number) => {
  switch (typeof x) {
    case 'number': return 0
  }
  x    // Unreachable code detected
}

const hel12 = (x: number) => {
  if(typeof x === 'number'){
    return 0;
  }
  x    // expect same error here!
}

Expected behavior:
in commnet

Actual behavior:
in commnet

Playground Link:
https://www.staging-typescript.org/play?#code/MYewdgzgLgBAFgUwDYCYYF4YAoAeAuGMAVwFsAjBAJwEoMA+GAbwCgYYIB3ASymDmygBPAA4IQAMxg5aLNm2ABDCAhgByYuSqqClBFCKUwMAAysYAXzM5ml5qEixESAIxpMuAhoo16TM13EsIVEJKQx0THVSb1VqWTldfUMTAG4zSzZrSyA

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions