This fails in TypeScript...
interface A {
getSomeBasicA():A;
getSomeBetterA():BetterA;
}
interface BetterA extends A {
getSomeBasicA():BetterA;
doFancyAStuff():void;
}
interface B extends A {
getSomeBetterA():BetterB;
}
interface BetterB extends B, BetterA {}
... with this message ...
error TS2430: Interface 'B' incorrectly extends interface 'A'.
The types returned by 'getSomeBetterA().getSomeBasicA()' are incompatible between these types.
Property 'doFancyAStuff' is missing in type 'A' but required in type 'BetterA'.
error TS2320: Interface 'BetterB' cannot simultaneously extend types 'B' and 'BetterA'.
Named property 'getSomeBasicA' of types 'B' and 'BetterA' are not identical.
error TS2320: Interface 'BetterB' cannot simultaneously extend types 'B' and 'BetterA'.
Named property 'getSomeBetterA' of types 'B' and 'BetterA' are not identical.
... while this works in Java ...
public interface A {
public A getSomeBasicA();
public BetterA getSomeBetterA();
}
public interface BetterA extends A {
public BetterA getSomeBasicA();
public void doFancyAStuff();
}
public interface B extends A {
public BetterB getSomeBetterA();
}
public interface BetterB extends B, BetterA {
}
... and I wonder why? Is it not type safe (how could it be broken, why does the Java compiler allow it)? Is there a name for the feature that one compiler supports and the other doesn't?