interface Array { flatMap(callbackFn: (value: T, index: number, array: T[]) => R[]): R[]; } ((proto) => { if (typeof proto.flatMap === "function") return; proto.flatMap = function flatMap(this: T[], callbackFn: (value: T, index: number, array: T[]) => R[]): R[] { let arrays = this.map(callbackFn); let result = Array.prototype.concat(...arrays); return result; } })(Array.prototype);