This one works as expected:
interface Array<T> {
foo(): number;
}
Array.prototype.foo = function(): number {
return 42;
}
var arr: string[] = ['a', 'b', 'c'];
var x = arr.foo();
But tsc throws an error for this one:
interface Array<T> {
foo(): number;
}
Array.prototype['foo'] = function(): number {
return 42;
}
var arr: string[] = ['a', 'b', 'c'];
var x = arr.foo();
export = x;
The error is: error TS2339: Property 'foo' does not exist on type 'string[]'.