The issue is as mentioned in the example. The following would fail, i.e. TS could not compile an implementation of a promise library (and it should compile):
interface Promise<Value> {
result: Value;
then<T2>(f: (v: Value) => Promise<T2>): Promise<T2>;
then<T2>(f: (v: Value) => T2): Promise<T2>;
}
class PromiseImpl<Value> implements Promise<Value> {
result: Value;
then<T2>(f: (v: Value) => Promise<T2>): Promise<T2>;
then<T2>(f: (v: Value) => T2): Promise<T2>;
then<T2>(f: (v: Value) => any): Promise<T2> {
return undefined;
}
}
The issue is different from being able to define. e.g. the following would compile (an interface definition):
interface Promise<Value> {
result: Value;
then<T2>(f: (v: Value) => Promise<T2>): Promise<T2>;
}
interface PromiseImpl<Value> extends Promise<Value> {
result: Value;
then<T2>(f: (v: Value) => Promise<T2>): Promise<T2>;
then<T2>(f: (v: Value) => T2): Promise<T2>;
then<T2>(f: (v: Value) => any): Promise<T2>;
}