@typescript-eslint/no-dupe-class-members
Disallow two class members with the same name
Also called typescript-eslint/no-dupe-class-members, typescript/no-dupe-class-members
If a class declares the same name twice, the last declaration wins and the first one is never used. Nothing fails at runtime, so the dead code stays and misleads anyone who reads it.
A getter and a setter with the same name are a pair and are allowed. So are a static member and an instance member with the same name. Overload signatures, which repeat the name without a body, aren't reported.
It's the TypeScript version of no-dupe-class-members. Unlike that rule, it skips members with a name in brackets, such as ["save"].
Configure#
Off by default. To turn it on:
[lint.rules]
"@typescript-eslint/no-dupe-class-members" = "error" # or "warn"Examples#
class Store {
save() {
return "first";
}
saveDuplicate name save.() {
return "second";
}
}class Store {
save(id: number): void;
save(name: string): void;
save(key: number | string): void {}
get size() {
return 0;
}
set size(value: number) {}
static reset() {}
reset() {}
clear() {}
["clear"]() {}
}When not to use it#
TypeScript reports duplicate members on its own. If you type check your code, you don't need this rule.