Enforce using the nullish coalescing operator (??) instead of logical operators.
// code-linter.json5
{
"rules": {
"@typescript-eslint/prefer-nullish-coalescing": "error"
}
} function getText1(): string | undefined {
return 'bar';
}
function getText2(): string | null {
return 'bar';
}
const foo1: string | undefined = getText1();
export const v1 = foo1 ?? 'a string';
const foo2: string | null = getText2();
export const v2 = foo2 ?? 'a string'; declare const a: string | null; declare const b: string | null; export const c = a || b;
plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.