`Result value must be used` check
See original GitHub issueHello.
Quite often while working with ImmutableJS
data structures and other immutable libraries people forget that values are immutable:
They can accidentally write:
obj.set('name', 'newName');
Instead of:
let newObj = obj.set('name', 'newName');
These errors are hard to discover and they are very annoying. I think that this problem can’t be solved by tslint
, so I propose to add some sort of "you must use the result"
check into the compiler. But right now I have no idea how I want it to be expressed in the language, so I create this issue mainly to start a discussion.
Rust lang, for example, solves a similar problem with #[must_use]
annotation. This is not exact what we want, but it’s a good example and shows that the problem is quite common.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:15
- Comments:22 (8 by maintainers)
Top Results From Across the Web
Value Check - Oracle
The Value Check processor compares the data in an attribute against a single value. There are a number of options for performing the...
Read more >How to correct a #VALUE! error - Microsoft Support
Excel shows the #VALUE! error when your formula includes cells that have different data types (text and numeric values). The #VALUE! error is...
Read more >P-Value: What It Is, How to Calculate It, and Why It Matters
In statistics, the p-value is the probability of obtaining results at least as extreme as ... The p-value hypothesis test does not necessarily...
Read more >How can I test that a value is "greater than or equal to" in ...
addMatchers( { toBeAtLeast: function () { return { compare: function ... You can use the function least to check if a value is...
Read more >S.3.1 Hypothesis Testing (Critical Value Approach)
If the test statistic is more extreme than the critical value, then the null ... To conduct the hypothesis test for the population...
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
Here is another example of a refactoring error that this type of check would prevent:
Consider having an onclick handler:
used like:
Now you refactor, adding some logging:
This refactor is wrong; your buttons now no longer have any effect and your web app is broken due to what’s logically a type error that TypeScript did not help prevent. The correct code has some added
()
function calls:Here, one needed to call
f(someArg)()
instead off(someArg)
; the latter returns a function that is then unused.If TypeScript had the ability to warn on unused return values, like Haskell and Rust can do with
-Wall
, this mistake would be impossible to make.After having been burnt by a library updating a method to be const/pure in a new major version, whereas it modified state previously: +1
Calling pure methods without using the return value almost certainly is a bug. So if the library author was able to indicate this in some standardized way (e.g. the
nodiscard
as suggested above), TypeScript might’ve been able to prevent this issue from happening to me.