Currently I am trying to write a prototype extension function. But it seems that nothing what I try works. Have for that reason also tried examples from others but they all give the same error: TypeError: array.remove is not a function.
Here is some code I put in my generic-utill file:
export {};
declare global {
interface Array<T> {
remove(elem: T): Array<T>;
}
}
Array.prototype.remove = function<T>(elem: T): T[] {
return this.filter(e => e !== elem);
};
And this in my service class:
const array = [1, 2, 3, 4];
const result = array.remove(1);
Could someone maybe explain what I am doing wrong since I don’t really understand what I am missing.