In this particular example, I'm extending the Array<T>
interface like so:
interface BetterArray<T> extends Array<T> {
push(this: BetterArray<T>, value: T): this;
}
Note for reference - Array<T>.push
is implemented like this
interface Array<T> {
push(...items: T[]): number;
}
But I get the following compile-time error:
Interface 'BetterArray' incorrectly extends interface 'T[]'.
Types of property 'push' are incompatible. Type '(this: BetterArray, value: T) => this' is not assignable to type '(...items: T[]) => number'. Type 'this' is not assignable to type 'number'. Type 'BetterArray' is not assignable to type 'number'.
Is there any way I can forcibly instruct TypeScript that I want to overwrite push on my interface (like member hiding in C#)?
Note - I'm using TypeScript 2.0
Further reading - it appears that this is purely down to return type - basically I want to enforce by interface, a new return type...
interface A {
fn(): number;
}
interface B extends A {
fn(): this;
}
Interface 'B' incorrectly extends interface 'A'. Types of property 'fn' are incompatible. Type '() => this' is not assignable to type '() => number'. Type 'this' is not assignable to type 'number'. Type 'B' is not assignable to type 'number'.