数组原型打字稿
问题描述:
我创造我自己的扩展阵列如下:数组原型打字稿
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