1
我創造我自己的擴展陣列如下:數組原型打字稿
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
在我的任何組件的智能感知的顯示我這些方法作爲擴展,但在調試時我得到了一個未定義例如:
events: Event[];
var result = this.events.count();
我應該在哪裏實現Array方法,以便它們可以從任何組件中看到?
相關:http://stackoverflow.com/a/14034242/215552 –
你是否已經加載了在調試項目中實際創建這些方法的模塊? – Bergi
它在不同的.ts文件中我已經在使用的組件中導出該文件 – miechooy