Trying to extend the functionality of the Array prototype in Typescript (1.8) through a module.
The modification to the prototype is being made in utils.ts file:
declare global {
interface Array<T> {
remove(obj: any): void;
}
}
Array.prototype.remove = function(obj) {
var idx = this.indexOf(obj);
if (idx > -1) {
this.splice(idx, 1);
}
}
Now, the goal is to implement this change globally in the main.ts file like this:
import {Array<T>.remove} from "./utils.ts"
let arr = ["an", "array"];
arr.remove("array");
While it's possible to import the interface declaration, the modification to the Array prototype is not reflected in the main.ts file. How can the prototype be altered and globally apply that "remove" functionality or somehow import it?