interface Promise { as(b: B): Promise tap(f: (t: T) => void): Promise; flatTap(f: (t: T) => Promise): Promise; tapError(e: (e: any) => void): Promise flatTapError(e: (e: any) => Promise): Promise } Promise.prototype.as = function (b: any) { return this.then(_ => b) } Promise.prototype.flatTap = function (cb: Function) { return this.then(o => cb(o).as(o)) } Promise.prototype.flatTapError = function (cb: Function) { return this.catch(e => cb(e).then((_: any) => { throw e })) } Promise.prototype.tap = function (cb: Function) { return this.then(t => { cb(t); return t }) } Promise.prototype.tap = function (cb: Function) { return this.then(t => { cb(t); return t }) }