You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across a very silly bug in my code which the Typescript compiler did not catch. Consider the following snippet of code:
class MyClass {
public /*get*/ flag(): boolean {
return false;
}
public doStuff() {
if(this.flag) {
alert('hello');
}
}
}
The alert will always be executed, because the property has been mis-declared as a method. Instead of invoking the getter and checking its return value, we instead evaluate the body as truthy.
While this behaviour is expected in many cases, it would be nice to have a compilation flag to enable additional checks, for example - noImplicitBool. It would require expressions in classic control structures (if, while, for) to be explicitly of the boolean type.
The flag should not affect the behaviour of the || operator, which is often used for coalescing values of arbitrary types.
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
I came across a very silly bug in my code which the Typescript compiler did not catch. Consider the following snippet of code:
The
alert
will always be executed, because the property has been mis-declared as a method. Instead of invoking the getter and checking its return value, we instead evaluate the body as truthy.While this behaviour is expected in many cases, it would be nice to have a compilation flag to enable additional checks, for example -
noImplicitBool
. It would require expressions in classic control structures (if
,while
,for
) to be explicitly of theboolean
type.The flag should not affect the behaviour of the
||
operator, which is often used for coalescing values of arbitrary types.The text was updated successfully, but these errors were encountered: