Wrong unused variable with logical assigment
See original GitHub issueBug Report
🔎 Search Terms
TS6133
🕗 Version & Regression Information
Version: 4.3.4 (nightly is also affected)
⏯ Playground Link
💻 Code
const f = () => {
let promise: Promise<unknown> | undefined = undefined; // error: TS6133: 'promise' is declared but its value is never read.
return () => {
promise ??= Promise.resolve().then(() => promise = undefined)
}
}
🙁 Actual behavior
error: TS6133: ‘promise’ is declared but its value is never read.
🙂 Expected behavior
Should be ok. Operator ??=
reads variable (as well as ||=
and other logical assignments)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
"Variable is assigned but its Value is never used" Warning
bool isSelected = false; if (true) isSelected = false;. I still get the compiler warning which clearly should serve as an assignment.
Read more >How to avoid annoying error "declared and not used"
I'm learning Go but I feel it is a bit annoying that when compiling, I should not leave any variable or package unused....
Read more >catch variables should not be flagged as unused with ... - GitHub
e should not be an error.
Read more >Incorrect highlight for "This value is never used" : CPP-20240
Local variable is only assigned but never accessed. It's true cause unused is never used (besides assignment); The value is never used. The...
Read more >Temporarily allow unused variables - Google Groups
Say, if I assign to a variable and never read it - that produces a compiler error. I realize I completely missed a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think
||=
and&&=
is also involved for same reason. Demo:(() => { let a = true; a ||= console.log('Executed')})()
will not output ‘Executed’The variable is not actually read (aka used) anywhere. That the operators evaluate the content of the variable does not count as it being used.