title: Relationship between a TypeScript class and an interface with the same name
body: <p>I'm having a bit of trouble locating any clear documentation or explanation for the seemingly-special relationship between a TypeScript class and an interface with the same name.</p>
  
  <ul>
  <li>What's the significance of an interface with the same name as a class?</li>
  <li>Why does a class that shares its name with an interface implement that interface automatically?</li>
  <li>Why does the compiler complain about my getter implementation of a readonly interface field when the class and interface have the same name, but accept the implementation if the names are different?</li>
  <li>Is there any canonical documentation addressing these questions?</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>// Co-named interface and class doesn't like readonly property implementation:
  
  interface Foo {
    readonly x: number; // Error: Duplicate identifier 'x'
    y: number;
  }
  
  class Foo {
    get x(): number { // Error: Duplicate identifier 'x'
      return 0;
    }
  
    y = 1;
  }
  
  // Same as above, but different class name + explicit `implements`
  
  class Bar implements Foo {
    get x(): number { // No error!
      return 0;
    }
  
    y = 1;
  }
  
  // Duplicating the first example, but explicitly implementing the co-named interface:
  
  interface Baz {
    readonly x: number; // Error: Duplicate identifier 'x'
    y: number;
  }
  
  class Baz implements Baz {
    get x(): number { // Error: Duplicate identifier 'x'
      return 0;
    }
  
    y = 1;
  }
  </code></pre>