1

I have created my own extensions to Array as below:

export interface Func<T, TResult> {
    (item: T): TResult;
}

declare global {
    interface Array<T> {
        where(predicate: Func<T, boolean>): Array<T>;
        single(predicate: Func<T, boolean>): T;
        first(predicate: Func<T, boolean>): T;
        take(predicate: Func<T, boolean>, count: number): Array<T>;
        countWhere(predicate: Func<T, boolean>): number;
        count(): number;
    }
}

Array.prototype.count = function <T>(): number {
    return this.length;
}

//others

In any of my component intellisense shows me these methods as extensions but while debugging I get undefined for example:

events: Event[];
var result = this.events.count();

Where should I implement Array methods so they could be visible from any component?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
miechooy
  • 3,178
  • 12
  • 34
  • 59

1 Answers1

0

Here are the things to check...

  1. Whether the file containing extensions loads
  2. Whether it loads in the correct order (i.e. before it is used)

Open up the developer tools in your web browser (usually F12) and select the "Network" tab.

Example Network Tab (Stack Overflow)

Run your application and review the JavaScript files that load.

You can check that the file containing your Array extensions is loaded - and that it is loaded before the file that depends on these extensions.

Fenton
  • 241,084
  • 71
  • 387
  • 401