Closed
Description
Repro
{
"rules": {
"@typescript-eslint/strict-boolean-expressions": [
2,
{
"ignoreRhs": true,
"allowNullable": true
}
]
}
}
{
declare const myString: string;
declare const myBoolean: boolean;
const expression = myBoolean && myString; // Expect: no error (thanks to `ignoreRhs`)
if (expression) {} // Expect: error
}
{
declare const myString: string;
declare const myBoolean: boolean;
if (myBoolean && myString) {} // Expect: error. Actual: no error. ❌
}
Additional Info
This does error as expected in TSLint (with the equivalent rule of the same name).
In the first example, the right-hand side of expression
will not be coerced (until it's later used in an if
statement), so it's safe to for it to be a non-boolean type.
In the second example however, the right-hand side of the condition in the if
statement will be coerced, so it's not safe for it to be a non-boolean type.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
2.4.0 |
@typescript-eslint/parser |
2.4.0 |
TypeScript |
3.6.4 |
ESLint |
6.5.1 |
node |
12.8.1 |
npm |
6.10.2 |