title: Extending Object.prototype with TypeScript
body: <p>I am currently working on a TypeScript API, which requires some additional features binding to the Object prototype (Object.prototype).</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>class Foo {
  
  }
  
  interface Object {
      GetFoo(): Foo;
      GetFooAsString(): string;
  }
  
  //This is problematic...
  Object.prototype.GetFoo = function() {
      return new Foo();
      // Note, this line is just for testing...I don't want my function to just return a blank instance of Foo!
  }
  
  //This is ok.
  Object.prototype.GetFooAsString = function () {
      return this.GetFoo().toString();
  }
  </code></pre>
  
  <p>You might want to try this directly at the <a href="http://www.typescriptlang.org/Playground/#src=class%20Foo%20%7B%0A%0A%7D%0A%0Ainterface%20Object%20%7B%0A%20%20%20%20GetFoo%28%29%3a%20Foo;%0A%20%20%20%20GetFooAsString%28%29%3a%20string;%0A%7D%0A%0A//This%20is%20problematic...%0AObject.prototype.GetFoo%20=%20function%28%29%20%7B%0A%20%20%20%20return%20new%20Foo%28%29;%0A%20%20%20%20//%20Note,%20this%20line%20is%20just%20for%20testing...I%20don%27t%20want%20my%20function%20to%20just%20return%20a%20blank%20instance%20of%20Foo!%0A%7D%0A%0A//This%20is%20ok.%0AObject.prototype.GetFooAsString%20=%20function%20%28%29%20%7B%0A%20%20%20%20return%20this.GetFoo%28%29.toString%28%29;%0A%7D">Playground</a>.</p>
  
  <p>As you can see, I have a class called <code>Foo</code> (not the actual object name I will be using). I have also extended the <code>Object</code> interface to include two new functions. Finally I have implemented the functions against the <code>prototype</code> (these work in pure JavaScript, it's just TypeScript that complains).</p>
  
  <p>Where I have annotated "<em>//this is problematic...</em>" TypeScript highlights this with a red squiggly, and shows the following error:</p>
  
  <pre><code>Cannot convert '() =&gt; Foo' to '{ (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; }': Call signatures of types '() =&gt; Foo' and '{ (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; (): Foo; }' are incompatible
  () =&gt; Foo
  </code></pre>
  
  <p>Either this is just a TypeScript bug (I know it's still in development phase, so a lot of the bugs need ironing out, and I have illustrated some of these on CodePlex already), or, I'm missing something.</p>
  
  <p>Why am I getting this issue?</p>
  
  <p>If it's not a TypeScript bug, how can I fix this?</p>