title: Extending a class results in types being used as values
body: <p>I have a 3rd party lib, <code>foo</code>, which exports the <code>Foo</code> class:</p>
  <pre><code>// Foo.ts
  export class Foo {
      constructor(
          public readonly name: string
      ) {}
  
  }
  
  // Foo.d.ts
  declare module &quot;foo&quot; {
      export class Foo {
          constructor(name: string);
      }
  }
  </code></pre>
  <p>Then I want to extend it with a <code>sayHi</code> method:</p>
  <pre><code>// AddHiToFooTypes.d.ts
  import &quot;foo&quot;;
  declare module &quot;foo&quot; {
      export interface Foo {
          sayHi(): void;
      }
  }
  
  // AddHiToFoo.ts
  import {Foo} from &quot;foo&quot;;
  import &quot;./AddHiToFooTypes&quot;;
  
  Foo.prototype.sayHi = function() {
      console.log(&quot;Hi from &quot;, this.name)
  }
  </code></pre>
  <p>This does what it is supposed to, now I can import both into a file and have the base <code>Foo</code> class as well as the <code>sayHi</code> method:</p>
  <pre><code>import { Foo } from &quot;foo&quot;;
  import &quot;addSayHiToFoo&quot;;
  
  // Foo.prototype.sayHi exists here
  </code></pre>
  <p>The problem is that I can not make an instance of <code>Foo</code>:</p>
  <pre><code>new Foo(); // Fails
  </code></pre>
  <p>The error is <code>'Foo' only refers to a type, but is being used as a value here.ts(2693)</code>
  meaning that typescript is now treating <code>Foo</code> as an interface rather than a class (you can not define it as a class in the <code>AddHiToFooTypes.d.ts</code> or that will overwrite everything else in the class).</p>
  <p>How do I keep <code>Foo</code> as a class while also adding new methods?</p>
  <p>Edit: This does work for 2 files right next to each other though:</p>
  <pre><code>// a.ts
  export class A{}
  
  // b.ts
  import &quot;./a&quot;;
  
  declare module &quot;./a&quot; {
      interface A {
          doStuff(): string
      }
  }
  
  
  import {A} from &quot;./a&quot;
  new A().doStuff()
  </code></pre>