// Default Options feature is not supported because it's basically impossible to write strongly-typed definitions for it. import * as http from 'http' import { URL } from 'url'; interface IOptionsBase { url: string | URL method?: string headers?: object core?: http.ClientRequestArgs followRedirects?: boolean stream?: boolean compression?: boolean timeout?: number hostname?: string port?: number path?: string } declare function phin(options: phin.IJSONResponseOptions | phin.IWithData | phin.IWithForm): Promise> declare function phin(options: phin.IStringResponseOptions | phin.IWithData | phin.IWithForm): Promise declare function phin(options: phin.IStreamResponseOptions | phin.IWithData | phin.IWithForm): Promise declare function phin(options: phin.IOptions | phin.IWithData | phin.IWithForm | string): Promise declare namespace phin { // Form and data property has been written this way so they're mutually exclusive. export type IWithData = T & { data: string | Buffer | object; } export type IWithForm = T & { form: { [index: string]: string } } export interface IJSONResponseOptions extends IOptionsBase { parse: 'json' } export interface IStringResponseOptions extends IOptionsBase { parse: 'string'; } export interface IStreamResponseOptions extends IOptionsBase { stream: true } export interface IOptions extends IOptionsBase { parse?: 'none' } export interface IJSONResponse extends http.IncomingMessage { body: T } export interface IStringResponse extends http.IncomingMessage { body: string; } export interface IStreamResponse extends http.IncomingMessage { stream: http.IncomingMessage } export interface IResponse extends http.IncomingMessage { body: Buffer; } // NOTE: Typescript cannot infer type of union callback on the consumer side // https://github.com/Microsoft/TypeScript/pull/17819#issuecomment-363636904 type IErrorCallback = (error: Error | string, response: null) => void type ICallback = (error: null, response: NonNullable) => void export let promisified: typeof phin export function unpromisified( options: IJSONResponseOptions | IWithData | IWithForm, callback: IErrorCallback | ICallback>): void export function unpromisified( options: IStringResponseOptions | IWithData | IWithForm, callback: IErrorCallback | ICallback): void export function unpromisified( options: IStreamResponseOptions | IWithData | IWithForm, callback: IErrorCallback | ICallback): void export function unpromisified( options: IOptions | IWithData | IWithForm | string, callback: IErrorCallback | ICallback): void } export = phin