Skip to content

Type of variable isn't widened inside a conditional inside a loop #46475

Closed
@icecream17

Description

@icecream17

Bug Report

🔎 Search Terms

ts2367 widen loop

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link

💻 Code

Edit: shorter version by gabritto

let code: 0 | 1 = 0
while (true) {
    code = code === 1 ? 0 : 1
}

And in practice:
image

🙁 Actual behavior

Error

🙂 Expected behavior

Since code could be changed in previous iterations of the loop, the condition is not always false, so there shouldn't be any error.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Control FlowThe issue relates to control flow analysisFix AvailableA PR has been opened for this issueRescheduledThis 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