From 09091ad257ed3fd5bbefa66312882492da3e6909 Mon Sep 17 00:00:00 2001 From: Shrey Jain Date: Mon, 22 Jan 2018 16:46:57 -0500 Subject: [PATCH] [superagent] Fixed definitions for parsers. (#23086) * Fixed definitions for parsers. * Different parser functions signatures for browser and node. --- types/superagent/index.d.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/types/superagent/index.d.ts b/types/superagent/index.d.ts index fdf23891cb..200046d439 100644 --- a/types/superagent/index.d.ts +++ b/types/superagent/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Nico Zelaya // Michael Ledin // Pap Lőrinc +// Shrey Jain // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -16,6 +17,12 @@ type CallbackHandler = (err: any, res: request.Response) => void; type Serializer = (obj: any) => string; +type BrowserParser = (str: string) => any; + +type NodeParser = (res: request.Response, callback: (err: Error | null, body: any) => void) => void; + +type Parser = BrowserParser | NodeParser; + type MultipartValueSingle = Blob | Buffer | fs.ReadStream | string | boolean | number; type MultipartValue = MultipartValueSingle | MultipartValueSingle[]; @@ -37,6 +44,7 @@ declare namespace request { agent(): SuperAgent; serialize: { [type: string]: Serializer }; + parse: { [type: string]: Parser }; } interface SuperAgent extends stream.Stream { @@ -55,7 +63,6 @@ declare namespace request { move(url: string, callback?: CallbackHandler): Req; notify(url: string, callback?: CallbackHandler): Req; options(url: string, callback?: CallbackHandler): Req; - parse(fn: (res: Response, callback: (err: Error | null, body: any) => void) => void): this; patch(url: string, callback?: CallbackHandler): Req; post(url: string, callback?: CallbackHandler): Req; propfind(url: string, callback?: CallbackHandler): Req; @@ -122,7 +129,7 @@ declare namespace request { on(name: 'error', handler: (err: any) => void): this; on(name: 'progress', handler: (event: ProgressEvent) => void): this; on(name: string, handler: (event: any) => void): this; - parse(fn: (res: Response, callback: (err: Error | null, body: any) => void) => void): this; + parse(parser: Parser): this; part(): this; pfx(cert: Buffer | string): this; pipe(stream: NodeJS.WritableStream, options?: object): stream.Writable;