interface Array { flatMap(callback: (t: T) => Array): Array; } Array.prototype.flatMap = function (f: Function) { return this.reduce((ys: any, x: any) => { return ys.concat(f.call(this, x)); }, []); };