<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="interface IFoo {
    func (str: string): number;
}

declare class CFoo implements IFoo {
    func2 (): void;
}"><pre class="notranslate"><span class="pl-k">interface</span> <span class="pl-smi">IFoo</span> <span class="pl-kos">{</span>
    <span class="pl-c1">func</span> <span class="pl-kos">(</span><span class="pl-s1">str</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span>: <span class="pl-smi">number</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">declare</span> <span class="pl-k">class</span> <span class="pl-smi">CFoo</span> <span class="pl-k">implements</span> <span class="pl-smi">IFoo</span> <span class="pl-kos">{</span>
    <span class="pl-c1">func2</span> <span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<blockquote>
<p dir="auto">error TS2420: Class 'CFoo' incorrectly implements interface 'IFoo'.<br>
Property 'func' is missing in type 'CFoo'.</p>
</blockquote>
<p dir="auto">Since this is just a declaration, we shouldn't have to manually redeclare all implemented methods, this should be implied by declaring that the class implements the interface. We are simply declaring that this class exists and it implements said interface and additionally defines these methods. The requirement for the class to implement those methods should only apply to the actual class definition.</p>
<p dir="auto">Hi, I realize that this has been <a href="http://stackoverflow.com/q/14583231/351836" rel="nofollow">asked on Stackoverflow</a> before and <a href="http://stackoverflow.com/a/14587529/351836" rel="nofollow">Ryan gave a short answer</a>, but I would really like to see this discussed more, since I believe this could be a huge time and ressource saver if it was implemented differently:</p>
<p dir="auto">I am trying to write a compact typescript definition file, but I am having troubles doing so for a larger project.</p>
<p dir="auto">My project has lots of interfaces that are implemented by a number of classes.</p>
<p dir="auto">From what I can see I always need to re"implement"/redeclare the methods of the interfaces in the classes like so:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    declare module someModule {

        interface InterfaceOne {
            /**
            * Some lengthy description
            */
            someStuff():any;
            /**
            * Some lengthy description
            */
            moreStuff():any;
        }

        class OneClass implements InterfaceOne {
            /**
            * Some lengthy description
            */
            someStuff():any;
            /**
            * Some lengthy description
            */
            moreStuff():any;
            /**
            * Even more description
            */
            classStuff(): any;
        }

        class TwoClass implements InterfaceOne {
            /**
            * Some lengthy description
            */
            someStuff():any;
            /**
            * Some lengthy description
            */
            moreStuff():any;
            /**
            * Even more description
            */
            classStuff(): any;
        }
    }   "><pre class="notranslate">    <span class="pl-k">declare</span> module <span class="pl-s1">someModule</span> <span class="pl-kos">{</span>

        <span class="pl-k">interface</span> <span class="pl-smi">InterfaceOne</span> <span class="pl-kos">{</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Some lengthy description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">someStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Some lengthy description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">moreStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>

        <span class="pl-k">class</span> <span class="pl-smi">OneClass</span> <span class="pl-k">implements</span> <span class="pl-smi">InterfaceOne</span> <span class="pl-kos">{</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Some lengthy description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">someStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Some lengthy description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">moreStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Even more description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">classStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>

        <span class="pl-k">class</span> <span class="pl-smi">TwoClass</span> <span class="pl-k">implements</span> <span class="pl-smi">InterfaceOne</span> <span class="pl-kos">{</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Some lengthy description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">someStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Some lengthy description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">moreStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
            <span class="pl-c">/**</span>
<span class="pl-c">            * Even more description</span>
<span class="pl-c">            */</span>
            <span class="pl-c1">classStuff</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">any</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>   </pre></div>
<p dir="auto">If I leave out the <code class="notranslate">someStuff</code> and <code class="notranslate">moreStuff</code> declarations from the interfaces in the class declarations<br>
I get this error:</p>
<blockquote>
<p dir="auto">error TS2137: Class TwoClass declares interface InterfaceOne but does not implement it:</p>
</blockquote>
<p dir="auto">So I always need to copy all of the declarations to each and every class that implements the interface.</p>
<p dir="auto">In his answer to the similar question Ryan wrote this:</p>
<blockquote>
<p dir="auto">Let's say you didn't have to write out the interface members:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  class Base { }
   class Derived extends Base { }

   interface Foo {
      method(t: number): Base;    
   }

   declare class FooImpl1 implements Foo {
       // Empty
   }

   declare class FooImpl2 implements Foo {
      public method(): Derived;
   }"><pre class="notranslate">  <span class="pl-k">class</span> <span class="pl-smi">Base</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>
   <span class="pl-k">class</span> <span class="pl-smi">Derived</span> <span class="pl-k">extends</span> <span class="pl-smi">Base</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>

   <span class="pl-k">interface</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
      <span class="pl-c1">method</span><span class="pl-kos">(</span><span class="pl-s1">t</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span>: <span class="pl-smi">Base</span><span class="pl-kos">;</span>    
   <span class="pl-kos">}</span>

   <span class="pl-k">declare</span> <span class="pl-k">class</span> <span class="pl-smi">FooImpl1</span> <span class="pl-k">implements</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
       <span class="pl-c">// Empty</span>
   <span class="pl-kos">}</span>

   <span class="pl-k">declare</span> <span class="pl-k">class</span> <span class="pl-smi">FooImpl2</span> <span class="pl-k">implements</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
      <span class="pl-k">public</span> <span class="pl-c1">method</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">Derived</span><span class="pl-kos">;</span>
   <span class="pl-kos">}</span></pre></div>
<p dir="auto">Is <code class="notranslate">FooImpl2</code> trying to declare an additional overload of <code class="notranslate">method</code>, or is <code class="notranslate">FooImpl2</code> implementing<br>
<code class="notranslate">method</code> using a signature that takes fewer parameters and returns a more derived type? Either<br>
would be a valid interpretation. You'd have to make rules for all sorts of cases like this so the<br>
programmer could specify what they actually meant, making the language less predictable.</p>
</blockquote>
<p dir="auto">I don't understand his arguments:</p>
<p dir="auto">First: for the vast majority of cases the <code class="notranslate">//Empty</code> case is the case that is totally _un_ambiguous: I have a class that implements Foo and thus I can call all methods from Foo, why do I need to redeclare all of them?</p>
<p dir="auto">Second: It's the same thing with classes, too, and there the existing rules seem to suffice: If I extend a class (in a definition .d.ts file) I don't have to reenumerate all the base type members either:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Base {
    baseMethod():any;
}

class Derived extends Base { 
    derivedMethod():any;
}

class Foo {
    public method(t: number): Base;    
}

class FooImpl1 extends Foo {
    // Empty - works! why not for interfaces?
}

class FooImpl2 extends Foo {
    public method(): Derived;
    public method(t: number): Base;    // need to redeclare in case of overload if I want to use that method!
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Base</span> <span class="pl-kos">{</span>
    <span class="pl-c1">baseMethod</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">Derived</span> <span class="pl-k">extends</span> <span class="pl-smi">Base</span> <span class="pl-kos">{</span> 
    <span class="pl-c1">derivedMethod</span><span class="pl-kos">(</span><span class="pl-kos">)</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-c1">method</span><span class="pl-kos">(</span><span class="pl-s1">t</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span>: <span class="pl-smi">Base</span><span class="pl-kos">;</span>    
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">FooImpl1</span> <span class="pl-k">extends</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-c">// Empty - works! why not for interfaces?</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">FooImpl2</span> <span class="pl-k">extends</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-c1">method</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">Derived</span><span class="pl-kos">;</span>
    <span class="pl-k">public</span> <span class="pl-c1">method</span><span class="pl-kos">(</span><span class="pl-s1">t</span>: <span class="pl-smi">number</span><span class="pl-kos">)</span>: <span class="pl-smi">Base</span><span class="pl-kos">;</span>    <span class="pl-c">// need to redeclare in case of overload if I want to use that method!</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">So why should this not work for interfaces, too?</p>
<p dir="auto">By the way I really don't understand why you cannot do the following if you <em>leave out</em> the redeclaration in the last line of <code class="notranslate">FooImpl2</code> above:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="new FooImpl2().method(2);  // TS2081: Supplied parameters do not match any signature of call target. TS2087: Could not select overload for 'call' expression."><pre class="notranslate"><span class="pl-k">new</span> <span class="pl-smi">FooImpl2</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">method</span><span class="pl-kos">(</span><span class="pl-c1">2</span><span class="pl-kos">)</span><span class="pl-kos">;</span>  <span class="pl-c">// TS2081: Supplied parameters do not match any signature of call target. TS2087: Could not select overload for 'call' expression.</span></pre></div>
<p dir="auto">If <code class="notranslate">FooImpl2</code> extends <code class="notranslate">Foo</code>, it <em>must</em> be possible to call <code class="notranslate">method(t:number)</code> from the base type <em>and</em> the method declared. After all it's all about library definition files (.d.ts) that declare how the library will behave, so the overload resolution happens at runtime and if multiple members are declared, then all of them should work and be available, shouldn't they?</p>
<p dir="auto">So back to the original question: Why can't <code class="notranslate">implements SomeInterface</code> behave like <code class="notranslate">extends SomeClass</code> in <code class="notranslate">.d.ts</code> declaration files? This would save us so much duplicated declarations and documentation, decrease the <code class="notranslate">d.ts</code> file size and speed up compilation and parsing, wouldn't it?</p>
<p dir="auto">Edit 2015-10-31: I had accidentally written that my desired way of writing the declaration would be "ambiguous" in the most common case - of course I meant "_un_ambiguous", otherwise this would all make no sense.</p>