Skip to content

Unreachable code breaks subsequent CFAΒ #61419

Closed
@Sainan

Description

@Sainan

πŸ”Ž Search Terms

control flow analysis, unreachable code

πŸ•— Version & Regression Information

Tested in 5.8.2

⏯ Playground Link

https://www.typescriptlang.org/play/?allowUnreachableCode=true#code/GYVwdgxgLglg9mABFApgZygCgIYC5FggC2ARigE6IA+i4AJisDGCnQJT4BucMdiA3gChEiGMESYo5ECjYDhIxORRQQ5MAG4FAXwViJ2RAEIAvCdpgGTFu3mLEEBBkQl8hUhUTnsW+47BocAA2KAB0QXAA5pgkbL6IutpAA

πŸ’» Code

function test(a: number | undefined): void {
  if (true) {
    return;
  }
  if (a !== undefined) {
    const b: number = a;
    console.log(b);
  }
}

πŸ™ Actual behavior

Type 'number | undefined' is not assignable to type 'number'.
  Type 'undefined' is not assignable to type 'number'.

πŸ™‚ Expected behavior

Code compiles without error.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions