mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[bent] Add types for overriding headers in request call (#41327)
* [bent] Add types for overriding headers in request call * [bent] fix my profile link
This commit is contained in:
committed by
Eli Barzilay
parent
72fa663add
commit
e760626f33
Vendored
+13
-7
@@ -1,6 +1,6 @@
|
||||
// Type definitions for bent 7.0
|
||||
// Project: https://github.com/mikeal/bent#readme
|
||||
// Definitions by: Ovyerus <https://github.com/me>
|
||||
// Definitions by: Ovyerus <https://github.com/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<string>;
|
||||
@@ -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<string>;
|
||||
declare function bent(baseUrl: string, type: 'buffer', ...args: bent.Options[]): bent.RequestFunction<Buffer | ArrayBuffer>;
|
||||
declare function bent(
|
||||
baseUrl: string,
|
||||
type: 'buffer',
|
||||
...args: bent.Options[]
|
||||
): bent.RequestFunction<Buffer | ArrayBuffer>;
|
||||
declare function bent(baseUrl: string, type: 'json', ...args: bent.Options[]): bent.RequestFunction<bent.Json>;
|
||||
declare function bent(baseUrl: string, ...args: bent.Options[]): bent.RequestFunction<bent.ValidResponse>;
|
||||
|
||||
@@ -33,18 +39,18 @@ declare function bent(...args: bent.Options[]): bent.RequestFunction<bent.ValidR
|
||||
// declare function bent(...args: (bent.Options | 'json')[]): bent.RequestFunction<Json>;
|
||||
|
||||
declare namespace bent {
|
||||
type RequestFunction<T extends ValidResponse> = (url: string, body?: RequestBody) => Promise<T>;
|
||||
type RequestFunction<T extends ValidResponse> = (url: string, body?: RequestBody, headers?: Headers) => Promise<T>;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user