From a37c56193ed4743499a80bd6e6c0fe5e6901c1e1 Mon Sep 17 00:00:00 2001 From: Jan-Pieter Zoutewelle Date: Thu, 28 Jul 2016 17:54:39 +0200 Subject: [PATCH 1/2] Added the .then Promise return for superagent --- superagent/superagent.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/superagent/superagent.d.ts b/superagent/superagent.d.ts index d16b13584f..67863520eb 100644 --- a/superagent/superagent.d.ts +++ b/superagent/superagent.d.ts @@ -101,6 +101,8 @@ declare module "superagent" { send(): this; set(field: string, val: string): this; set(field: Object): this; + then(onfulfilled?: (value: Response) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; + then(onfulfilled?: (value: Response) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; timeout(ms: number): this; type(val: string): this; use(fn: Function): this; From 199acf46b3b6c8e047417df20e551719c5c4979d Mon Sep 17 00:00:00 2001 From: Jan-Pieter Zoutewelle Date: Tue, 2 Aug 2016 18:40:24 +0200 Subject: [PATCH 2/2] Superagent request inherits Promise --- superagent/superagent-tests.ts | 6 +++++ superagent/superagent.d.ts | 6 ++--- .../supertest-as-promised.d.ts | 25 +------------------ 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/superagent/superagent-tests.ts b/superagent/superagent-tests.ts index 58b6840440..d61e411c85 100644 --- a/superagent/superagent-tests.ts +++ b/superagent/superagent-tests.ts @@ -279,3 +279,9 @@ request .attach('image', 'path/to/tobi.png') .on('error', (err: any) => {}) .end(callback); + +//Promise +request + .get('/search') + .then((response) => {}) + .catch((error) => {}); \ No newline at end of file diff --git a/superagent/superagent.d.ts b/superagent/superagent.d.ts index 67863520eb..6217809a85 100644 --- a/superagent/superagent.d.ts +++ b/superagent/superagent.d.ts @@ -1,4 +1,4 @@ -// Type definitions for SuperAgent v1.4.0 +// Type definitions for SuperAgent v2.0.0 // Project: https://github.com/visionmedia/superagent // Definitions by: Alex Varju // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -80,7 +80,7 @@ declare module "superagent" { get(header: string): string; } - interface Request /* extends NodeJS.WritableStream */ { + interface Request extends Promise /* extends NodeJS.WritableStream */ { abort(): void; accept(type: string): this; attach(field: string, file: string, filename?: string): this; @@ -101,8 +101,6 @@ declare module "superagent" { send(): this; set(field: string, val: string): this; set(field: Object): this; - then(onfulfilled?: (value: Response) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; - then(onfulfilled?: (value: Response) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; timeout(ms: number): this; type(val: string): this; use(fn: Function): this; diff --git a/supertest-as-promised/supertest-as-promised.d.ts b/supertest-as-promised/supertest-as-promised.d.ts index c16be4cb97..89bc3e5525 100644 --- a/supertest-as-promised/supertest-as-promised.d.ts +++ b/supertest-as-promised/supertest-as-promised.d.ts @@ -22,7 +22,7 @@ declare module "supertest-as-promised" { interface Response extends supertest.Response { } - interface Test extends Promise, supertest.Test, supersgent.Request { + interface Test extends supertest.Test, supersgent.Request { toPromise(): PromiseBlurbird; } @@ -33,27 +33,4 @@ declare module "supertest-as-promised" { } export = supertestAsPromised - // from core-js.d.ts - /** - * Represents the completion of an asynchronous operation - */ - interface Promise { - /** - * Attaches callbacks for the resolution and/or rejection of the Promise. - * @param onfulfilled The callback to execute when the Promise is resolved. - * @param onrejected The callback to execute when the Promise is rejected. - * @returns A Promise for the completion of which ever callback is executed. - */ - then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => TResult | PromiseLike): Promise; - then(onfulfilled?: (value: T) => TResult | PromiseLike, onrejected?: (reason: any) => void): Promise; - - /** - * Attaches a callback for only the rejection of the Promise. - * @param onrejected The callback to execute when the Promise is rejected. - * @returns A Promise for the completion of the callback. - */ - catch(onrejected?: (reason: any) => T | PromiseLike): Promise; - catch(onrejected?: (reason: any) => void): Promise; - } - }