microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.08k stars 12.37k forks source link

report unused call results (Γ  la pyright) #54149

Closed FrancescElies closed 1 year ago

FrancescElies commented 1 year ago

Suggestion

In pyright there is reportUnusedCallResult but I couldn't find anything similar in TypeScript: TSConfig Reference, please correct me if I missed it.

πŸ” Search Terms

βœ… Viability Checklist

My suggestion meets these guidelines:

⭐ Suggestion

A similar option to pyright's reportUnusedCallResult could be added and being disabled it's default state and maybe enabled with strict flag?

πŸ“ƒ Motivating Example

// some code

get_chichi()

// more code

One reads this and wonders, why would one _getchichi here, chichi is not used anywhere.

πŸ’» Use Cases

Reminding the developer about unused call results makes it harder to see code like in the example above.

One problem I see with the proposal above is that there seems to be no convention in javascript for throwaway variables, but according to What is the equivalent of python's _ in javascript? - Stack Overflow and naming - What's the idiomatic name for a throwaway variable? - Software Engineering Stack Exchange dummy, temp, trash, black_hole, garbage seem to be widely used.

After tsc complains about the code above one would be forced to either remove that call, assign the result and use it or assign it to a throwaway variable.

MartinJohns commented 1 year ago

This sounds better suited as a linter rule instead of being part of the compiler. But I'd expect the false positives to be immensely.

FrancescElies commented 1 year ago

you are right, closing, I'll bring this to a linter project we end up using, thanks