Skip to content

Statements in class static blocks do not narrow types #44949

Closed
@AumyF

Description

@AumyF

Bug Report

🔎 Search Terms

control flow analysis, class static blocks

🕗 Version & Regression Information

  • v4.4.0-beta
  • v4.4.0-dev.20210708
  • This is the behavior in every version I tried, and I reviewed the proposal
  • I was unable to test this on prior versions because class static blocks were added in 4.4.0

⏯ Playground Link

Playground link with relevant code

💻 Code

let foo: number;

class C {
  static {
    foo = 3;
  }
}

console.log(foo);

🙁 Actual behavior

An error Variable 'foo' is used before being assigned.(2454) occurs at line 10, console.log(foo).

🙂 Expected behavior

Code compiles without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do thisRescheduledThis issue was previously scheduled to an earlier milestone

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions