我已经创建了我自己的Array扩展,如下所示:
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
在我的任何组件中,intellisense都将这些方法显示为扩展,但在调试时我得到了未定义的例如:
events: Event[];
var result = this.events.count();
我应该在哪里实现Array方法,以便可以从任何组件中看到它们?