I've encountered a common pitfall (especially with autocomplete) while testing a function return value. There are instances when I forget to include the parentheses ()
at the end, causing it to always return true.
class Foo {
public bar(): boolean {
// Return true or false based on certain logic
}
}
let foo = new Foo();
if (foo.bar) {
// UNINTENDED
// Always returns true because "foo.bar" is a function object
}
if (foo.bar()) {
// INTENDED
// Returns either true or false depending on the logic within "foo.bar"
}
Is there a way to receive notifications/warnings when using the former approach? During debugging, it's not always obvious that I missed the function call, making it challenging to identify the problem. Alternatively, are there better coding practices to prevent this issue?
As a user of VS Code, I am open to any linting tools or suggestions that can help alert me about this problem.