Extending methods overloads in derived interfaces

Topics: General, Language Specification
Dec 23, 2013 at 7:06 PM
Spec:
7.1 Interface Declarations
...
The following constraints must be satisfied by an interface declaration or otherwise a compile-time error occurs:
...
  • Inherited properties with the same name must be identical (section 3.8.2).
I found the rule very harmful in case of property is a function.
For example:
interface A {
    f(): void;
    f(a: number): void;
}
interface B extends A {
    f(b: boolean): void;
}
We've got error: "Interface 'B' cannot extend interface 'A': Types of property 'f' of types 'B' and 'A' are incompatible: Call signatures of types '(b: boolean) => void' and '{ (): void; (a: number): void; }' are incompatible: Call signature expects 0 or fewer parameters."

Can't understand why TS can't extend property f by new call signature provided by B interface. Of course it will change of the property f.
Let's imagine TS allow such inheritance. We'll get an interface identical to C:
interface C {
    f(): void;
    f(a: number): void;
    f(b: boolean): void;
}
Now we can test all the principles of inheritance:
var a: A, c: C;
a = c;      // any C is A, ok
a.f = c.f;  // any (typeof c.f) is (typeof a.f), ok
So why such rule was defined in the language? Is it possible to allow extending function overloads in derived interfaces (and classes)?
Developer
Dec 28, 2013 at 2:21 AM
The rule you reference above applies to inherited properties and really only comes into play in interfaces with multiple base interfaces that define properties by the same name. In your example the f property is redefined in B, and thus not inherited from A. Keep in mind here that the redefinition in B replaces the definition in A. The definitions aren't merged and that's why you're getting an error. If you define f in B the same was as you have in C it all works.