From e760626f33307eadb769c7ff63e9215f83a439d7 Mon Sep 17 00:00:00 2001 From: Michael Mitchell Date: Fri, 17 Jan 2020 07:12:06 +1100 Subject: [PATCH] [bent] Add types for overriding headers in request call (#41327) * [bent] Add types for overriding headers in request call * [bent] fix my profile link --- types/bent/index.d.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/types/bent/index.d.ts b/types/bent/index.d.ts index 6730590d8c..61943b623b 100644 --- a/types/bent/index.d.ts +++ b/types/bent/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for bent 7.0 // Project: https://github.com/mikeal/bent#readme -// Definitions by: Ovyerus +// Definitions by: Ovyerus // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.7 @@ -11,7 +11,9 @@ import { PassThrough, Stream } from 'stream'; type HttpMethod = 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'; type StatusCode = number; type BaseUrl = string; -interface Headers { [key: string]: any; } +interface Headers { + [key: string]: any; +} // Type first declare function bent(type: 'string', ...args: bent.Options[]): bent.RequestFunction; @@ -20,7 +22,11 @@ declare function bent(type: 'json', ...args: bent.Options[]): bent.RequestFuncti // Method or url first declare function bent(baseUrl: string, type: 'string', ...args: bent.Options[]): bent.RequestFunction; -declare function bent(baseUrl: string, type: 'buffer', ...args: bent.Options[]): bent.RequestFunction; +declare function bent( + baseUrl: string, + type: 'buffer', + ...args: bent.Options[] +): bent.RequestFunction; declare function bent(baseUrl: string, type: 'json', ...args: bent.Options[]): bent.RequestFunction; declare function bent(baseUrl: string, ...args: bent.Options[]): bent.RequestFunction; @@ -33,18 +39,18 @@ declare function bent(...args: bent.Options[]): bent.RequestFunction; declare namespace bent { - type RequestFunction = (url: string, body?: RequestBody) => Promise; + type RequestFunction = (url: string, body?: RequestBody, headers?: Headers) => Promise; type Options = HttpMethod | StatusCode | Headers | BaseUrl; type RequestBody = string | Stream | Buffer | ArrayBuffer | Json; type NodeResponse = PassThrough & { statusCode: number; statusMessage: string; - headers: Headers + headers: Headers; }; - type FetchResponse = Response & {statusCode: number}; + type FetchResponse = Response & { statusCode: number }; type BentResponse = NodeResponse | FetchResponse; - type Json = { [key: string]: any; [key: number]: any; } | any[]; + type Json = { [key: string]: any; [key: number]: any } | any[]; type ValidResponse = BentResponse | string | Buffer | ArrayBuffer | Json; }