New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong unused variable with logical assigment #44802
Comments
|
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. |
|
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
It might be true if variable was local. |
|
The other compound operators You could imagine writing let done = undefined;
done ??= doSomething();
done ??= doSomethingElse();
done ??= doAnotherThing();as some kind of weird control flow scheme. The final statement will always be suspect, but not in an "unused variable" kind of way |
|
I think |
π |
|
consider the case of ecmascript private fields: export class ReadsPrivateInTruth {
#priv = false;
async readsActually() {
this.#priv ||= await window.expensiveOp();
}
}
declare global {
interface Window {
expensiveOp(): Promise<boolean>;
}
}
|
|
I was going to post this as a separate issue, but then I found this. Using This issue is similar to #51371 and #42422 which were about β― Playground Linkπ» Codeπ Actual behaviorThe error π Expected behavior
I mean. No error. It's a valid strat! |
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
π 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)The text was updated successfully, but these errors were encountered: