complete/no-unnecessary-assignment
💼 This rule is enabled in the ✅ recommended config.
📝 Disallows useless assignments.
💭 This rule requires type information.
Rule Details
Section titled “Rule Details”Sometimes, refactoring can lead to assignment statements that were once useful
but are now redundant. This rule helps you clean up the dead code in a similar
way that the
@typescript-eslint/no-unnecessary-condition
rule does.
// Baddeclare let foo: 1;declare let bar: 1;foo = bar;
// Baddeclare let foo: number;foo += 0;
// Baddeclare let foo: string;foo += "";
// Baddeclare const foo: boolean;const bar = foo || false;const baz = foo && true;
// Baddeclare const foo: number;const bar = foo || 0;
// Baddeclare const foo: string;const bar = foo || "";
// Baddeclare const foo: string | null;const bar = foo ?? null;
// Baddeclare const foo: string | undefined;const bar = foo ?? undefined;Note that while “<<” is technically a useless operator when combined with 0, this rule will not report on it so that bit flag enums will not cause false positives.
Options
Section titled “Options”This rule is not configurable.
