Skip to content

Files

Latest commit

 

History

History
39 lines (31 loc) · 623 Bytes

no-dupe-class-members.md

File metadata and controls

39 lines (31 loc) · 623 Bytes

Pattern: Duplicate class member declaration

Issue: -

Description

When class members have the same name, the last declaration silently overwrites previous ones. This can lead to unexpected behavior, especially when mixing methods and properties with the same name.

Examples

Example of incorrect code:

class A {
  foo() {
    console.log("foo");
  }
  foo = 123;  // Overwrites foo method
}

class B {
  bar() {}
  bar() {}  // Duplicate method
}

Example of correct code:

class A {
  foo() {
    console.log("foo");
  }
  bar = 123;
}

class B {
  bar() {}
  baz() {}
}