Disallow certain types in boolean expressions.
// code-linter.json5
{
"rules": {
"@typescript-eslint/strict-boolean-expressions": "error"
}
} // nullable values should be checked explicitly against null or undefined
function getNum(): number | undefined {
return undefined;
}
const num: number | undefined = getNum();
if (num !== undefined) {
console.log('num is defined');
}
function getStr(): string | null {
return 'null';
}
const str: string | null = getStr();
if (str !== null) {
console.log('str is not empty');
} // nullable values should be checked explicitly against null or undefined
function getNum(): number | undefined {
return undefined;
}
const num: number | undefined = getNum();
if (num) {
console.log('num is defined');
}
function getStr(): string | null {
return 'null';
}
const str: string | null = getStr();
if (str) {
console.log('str is not empty');
} plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.