🔎 Search Terms
uninitialized, local, use before assign, control flow
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240925#code/DYUwLgBAZg9jBcEDOYBOBLAdgcwNwCh8BjGTFZcAMTggF4IAKASkQDcZ0ATOgPggG98ECOiiNYMAHSgcYABYQAPBACMTAUOHQa9AOQTdBYQF98xgvhAAPAA4xUkfqaA
💻 Code
letfoo: string;constsetFoo=(): void=>{if(foo.length<1){foo='foo';}};export{}🙁 Actual behavior
No TS Error
🙂 Expected behavior
Variable 'foo' is used before being assigned.(2454)
Additional information about the issue
(this error is correctly reported if we never assign at all, as below)
letfoo: string;constsetFoo=(): void=>{if(foo.length<1){}};export{}Related, #60064.
Otherwise this can be solved by not considering assignments which occur unconditionally after a read.
🔎 Search Terms
uninitialized, local, use before assign, control flow
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240925#code/DYUwLgBAZg9jBcEDOYBOBLAdgcwNwCh8BjGTFZcAMTggF4IAKASkQDcZ0ATOgPggG98ECOiiNYMAHSgcYABYQAPBACMTAUOHQa9AOQTdBYQF98xgvhAAPAA4xUkfqaA
💻 Code
🙁 Actual behavior
No TS Error
🙂 Expected behavior
Variable 'foo' is used before being assigned.(2454)
Additional information about the issue
(this error is correctly reported if we never assign at all, as below)
Related, #60064.
Otherwise this can be solved by not considering assignments which occur unconditionally after a read.