Skip to content

False "variable is used before being assigned" error #47402

@sempasha

Description

@sempasha

Bug Report

🔎 Search Terms

Variable is used before being assigned ts(2454)

🕗 Version & Regression Information

According to TypeScript Playground error appears for TypeScript versions >= 3.3.3 && <= 4.5.4 and for latest nightly 4.6.4-dev.20220112. For versions ``, 3.5.1 and `3.6.3` no error happens.

⏯ Playground Link

Playground link with relevant code

💻 Code

let value: 'fail' | 'ok';
try {
  value = 'ok';
} catch (error) {
  value = 'fail';
} finally {
  console.log(value);
}

🙁 Actual behavior

Error Variable 'status' is used before being assigned.ts(2454) at finally block.

🙂 Expected behavior

Expect provided code sample has no error at finally block, because variable status will be surely initialized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions