javascripttypescripteslinttypescript-eslint

TypeScript Disallow Unecessary optional chain expression


Is there an es lint rule or typescript config to disallow the following ?

let s: string;
s = 'a';
s?.toLocaleLowerCase();

In my opinion, s is not nullable so no need to do optional chain assertion, it just confuses other developers


Solution

  • The typescript-eslint/no-unnecessary-condition rule does this.