// Type definitions for got 7.1 // Project: https://github.com/sindresorhus/got#readme // Definitions by: BendingBender // Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 /// import { Url } from 'url'; import * as http from 'http'; import * as nodeStream from 'stream'; export = got; declare class RequestError extends StdError { name: 'RequestError'; } declare class ReadError extends StdError { name: 'ReadError'; } declare class ParseError extends StdError { name: 'ParseError'; statusCode: number; statusMessage: string; } declare class HTTPError extends StdError { name: 'HTTPError'; statusCode: number; statusMessage: string; headers: http.IncomingHttpHeaders; } declare class MaxRedirectsError extends StdError { name: 'MaxRedirectsError'; statusCode: number; statusMessage: string; redirectUrls: string[]; } declare class UnsupportedProtocolError extends StdError { name: 'UnsupportedProtocolError'; } declare class StdError extends Error { code?: string; host?: string; hostname?: string; method?: string; path?: string; protocol?: string; url?: string; response?: any; } declare const got: got.GotFn & Record<'get' | 'post' | 'put' | 'patch' | 'head' | 'delete', got.GotFn> & { stream: got.GotStreamFn & Record<'get' | 'post' | 'put' | 'patch' | 'head' | 'delete', got.GotStreamFn> RequestError: typeof RequestError ReadError: typeof ReadError ParseError: typeof ParseError HTTPError: typeof HTTPError MaxRedirectsError: typeof MaxRedirectsError UnsupportedProtocolError: typeof UnsupportedProtocolError }; declare namespace got { interface GotFn { (url: GotUrl): GotPromise; (url: GotUrl, options: GotJSONOptions): GotPromise; (url: GotUrl, options: GotFormOptions): GotPromise; (url: GotUrl, options: GotFormOptions): GotPromise; (url: GotUrl, options: GotBodyOptions): GotPromise; (url: GotUrl, options: GotBodyOptions): GotPromise; } type GotStreamFn = (url: GotUrl, options?: GotOptions) => GotEmitter & nodeStream.Duplex; type GotUrl = string | http.RequestOptions | Url; interface GotBodyOptions extends GotOptions { body?: string | Buffer | nodeStream.Readable; } interface GotJSONOptions extends GotOptions { body?: object; form?: boolean; json: true; } interface GotFormOptions extends GotOptions { body?: {[key: string]: any}; form: true; json?: boolean; } interface TimoutRequestOptions extends http.RequestOptions { timeout?: any; } interface GotOptions extends TimoutRequestOptions { encoding?: E; query?: string | object; timeout?: number | TimeoutOptions; retries?: number | RetryFunction; followRedirect?: boolean; decompress?: boolean; useElectronNet?: boolean; } interface TimeoutOptions { connect?: number; socket?: number; request?: number; } type RetryFunction = (retry: number, error: any) => number; interface Response extends http.IncomingMessage { body: B; url: string; requestUrl: string; redirectUrls?: string[]; } type GotPromise = Promise> & { cancel(): void }; interface GotEmitter { addListener(event: 'request', listener: (req: http.ClientRequest) => void): this; addListener(event: 'response', listener: (res: http.IncomingMessage) => void): this; addListener(event: 'redirect', listener: (res: http.IncomingMessage, nextOptions: GotOptions & Url) => void): this; addListener(event: 'error', listener: (error: GotError, body?: any, res?: http.IncomingMessage) => void): this; on(event: 'request', listener: (req: http.ClientRequest) => void): this; on(event: 'response', listener: (res: http.IncomingMessage) => void): this; on(event: 'redirect', listener: (res: http.IncomingMessage, nextOptions: GotOptions & Url) => void): this; on(event: 'error', listener: (error: GotError, body?: any, res?: http.IncomingMessage) => void): this; once(event: 'request', listener: (req: http.ClientRequest) => void): this; once(event: 'response', listener: (res: http.IncomingMessage) => void): this; once(event: 'redirect', listener: (res: http.IncomingMessage, nextOptions: GotOptions & Url) => void): this; once(event: 'error', listener: (error: GotError, body?: any, res?: http.IncomingMessage) => void): this; prependListener(event: 'request', listener: (req: http.ClientRequest) => void): this; prependListener(event: 'response', listener: (res: http.IncomingMessage) => void): this; prependListener(event: 'redirect', listener: (res: http.IncomingMessage, nextOptions: GotOptions & Url) => void): this; prependListener(event: 'error', listener: (error: GotError, body?: any, res?: http.IncomingMessage) => void): this; prependOnceListener(event: 'request', listener: (req: http.ClientRequest) => void): this; prependOnceListener(event: 'response', listener: (res: http.IncomingMessage) => void): this; prependOnceListener(event: 'redirect', listener: (res: http.IncomingMessage, nextOptions: GotOptions & Url) => void): this; prependOnceListener(event: 'error', listener: (error: GotError, body?: any, res?: http.IncomingMessage) => void): this; removeListener(event: 'request', listener: (req: http.ClientRequest) => void): this; removeListener(event: 'response', listener: (res: http.IncomingMessage) => void): this; removeListener(event: 'redirect', listener: (res: http.IncomingMessage, nextOptions: GotOptions & Url) => void): this; removeListener(event: 'error', listener: (error: GotError, body?: any, res?: http.IncomingMessage) => void): this; } type GotError = RequestError | ReadError | ParseError | HTTPError | MaxRedirectsError | UnsupportedProtocolError; }