noDuplicateClassMembers
诊断类别:lint/suspicious/noDuplicateClassMembers
¥Diagnostic Category: lint/suspicious/noDuplicateClassMembers
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-dupe-class-members
¥Same as:
no-dupe-class-members
-
与以下相同:
@typescript-eslint/no-dupe-class-members
¥Same as:
@typescript-eslint/no-dupe-class-members
禁止重复的类成员。
¥Disallow duplicate class members.
如果类成员中有同名声明,则最后一个声明将默默覆盖其他声明。它可能导致意外行为。
¥If there are declarations of the same name among class members, the last declaration overwrites other declarations silently. It can cause unexpected behaviours.
¥Examples
¥Invalid
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate class member name “bar”
1 │ class Foo {
2 │ bar() { }
> 3 │ bar() { }
│ ^^^^^^^^^
4 │ }
5 │
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate class member name “bar”
1 │ class Foo {
2 │ bar() { }
> 3 │ get bar() { }
│ ^^^^^^^^^^^^^
4 │ }
5 │
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate class member name “bar”
1 │ class Foo {
2 │ bar;
> 3 │ bar() { }
│ ^^^^^^^^^
4 │ }
5 │
code-block.js:3:3 lint/suspicious/noDuplicateClassMembers ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate class member name “bar”
1 │ class Foo {
2 │ static bar() { }
> 3 │ static bar() { }
│ ^^^^^^^^^^^^^^^^
4 │ }
5 │
¥Valid
¥Related links