question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong unused variable with logical assigment

See original GitHub issue

Bug Report

🔎 Search Terms

TS6133

🕗 Version & Regression Information

Version: 4.3.4 (nightly is also affected)

⏯ Playground Link

https://www.typescriptlang.org/play?noUnusedLocals=true&ts=4.3.4&strict=true#code/MYewdgzgLgBAZjAvDAFASiQPhgbwFAyEwA2AprAA4BOIAtgJYSkBcMACjQ0wDwCuYAazAgA7mGwAfGPwAmpOPTCkZSaWDkKlMgNwEiVcryphUGRNnxErManUakYAfkfIOdpgDoDEEMQBupOgeUAAWpGAo6Fg2nPaqsvKKymh6hAC+eGlAA

💻 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
leonovalexcommented, Jul 30, 2021

I think ||= and &&= is also involved for same reason. Demo: (() => { let a = true; a ||= console.log('Executed')})() will not output ‘Executed’

1reaction
MartinJohnscommented, Jun 29, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found