Repro
Playground
{
"rules": {
"@typescript-eslint/no-unnecessary-boolean-literal-compare": [
"error",
{
allowComparingNullableBooleansToTrue: false,
allowComparingNullableBooleansToFalse: false,
},
],
}
}
const isTrue = (x: boolean | undefined): boolean => x === true;
Expected Result
I would've expected either one of the following fixes to be output
// fall back to false, since undefined is falsey
const isTrue = (x: boolean | undefined): boolean => x ?? false;
// coerce to boolean
const isTrue = (x: boolean | undefined): boolean => !!x;
// convert to boolean
const isTrue = (x: boolean | undefined): boolean => Boolean(x);
// leave as-is
const isTrue = (x: boolean | undefined): boolean => x === true;
Actual Result
const isTrue = (x: boolean | undefined): boolean => x;
Additional Info
The TypeScript compiler now gives an error:
Type 'boolean | undefined' is not assignable to type 'boolean'.
Type 'undefined' is not assignable to type 'boolean'. ts(2322)
Versions
| package |
version |
@typescript-eslint/eslint-plugin |
4.29.2 |
@typescript-eslint/parser |
4.29.2 |
TypeScript |
4.3.5 |
ESLint |
7.30.0 |
node |
14.16.1 |
Repro
Playground
Expected Result
I would've expected either one of the following fixes to be output
Actual Result
Additional Info
The TypeScript compiler now gives an error:
Versions
@typescript-eslint/eslint-plugin4.29.2@typescript-eslint/parser4.29.2TypeScript4.3.5ESLint7.30.0node14.16.1