From 496ed1655782f343a14f4a7315a3733de06e5979 Mon Sep 17 00:00:00 2001 From: Keimeno Date: Thu, 9 Jan 2020 15:15:24 +0100 Subject: [PATCH 1/4] added AxiosHeaders type for autosuggestions on headers --- headers.ts | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.d.ts | 8 ++-- 2 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 headers.ts diff --git a/headers.ts b/headers.ts new file mode 100644 index 0000000000..1a130f8ac0 --- /dev/null +++ b/headers.ts @@ -0,0 +1,105 @@ +type LooseObject = object & { + [key: string]: string; +}; + +type AxiosHeaders = LooseObject & { + Accept?: string; + 'Accept-CH'?: string; + 'Accept-CH-Lifetime'?: string; + 'Accept-Charset'?: string; + 'Accept-Encoding'?: string; + 'Accept-Language'?: string; + 'Accept-Patch'?: string; + 'Accept-Ranges'?: string; + 'Access-Control-Allow-Credentials'?: string; + 'Access-Control-Allow-Headers'?: string; + 'Access-Control-Allow-Methods'?: string; + 'Access-Control-Allow-Origin'?: string; + 'Access-Control-Expose-Headers'?: string; + 'Access-Control-Max-Age'?: string; + 'Access-Control-Request-Headers'?: string; + 'Access-Control-Request-Method'?: string; + Age?: string; + Allow?: string; + 'Alt-Svc'?: string; + Authorization?: string; + 'Cache-Control'?: string; + 'Clear-Site-Data'?: string; + Connection?: string; + 'Content-Disposition'?: string; + 'Content-Encoding'?: string; + 'Content-Language'?: string; + 'Content-Length'?: string; + 'Content-Location'?: string; + 'Content-Range'?: string; + 'Content-Security-Policy'?: string; + 'Content-Security-Policy-Report-Only'?: string; + 'Content-Type'?: string; + Cookie?: string; + Cookie2?: string; + 'Cross-Origin-Resource-Policy'?: string; + DNT?: string; + DPR?: string; + Date?: string; + 'Device-Memory'?: string; + Digest?: string; + ETag?: string; + 'Early-Data'?: string; + Expect?: string; + 'Expect-CT'?: string; + Expires?: string; + 'Feature-Policy'?: string; + Forwarded?: string; + From?: string; + Host?: string; + 'If-Match'?: string; + 'If-Modified-Since'?: string; + 'If-None-Match'?: string; + 'If-Range'?: string; + 'If-Unmodified-Since'?: string; + Index?: string; + 'Keep-Alive'?: string; + 'Large-Allocation'?: string; + 'Last-Modified'?: string; + Link?: string; + Location?: string; + Origin?: string; + Pragma?: string; + 'Proxy-Authenticate'?: string; + 'Proxy-Authorization'?: string; + 'Public-Key-Pins'?: string; + 'Public-Key-Pins-Report-Only'?: string; + Range?: string; + Referer?: string; + 'Referrer-Policy'?: string; + 'Retry-After'?: string; + 'Save-Data'?: string; + 'Sec-WebSocket-Accept'?: string; + Server?: string; + 'Server-Timing'?: string; + 'Set-Cookie'?: string; + 'Set-Cookie2'?: string; + SourceMap?: string; + 'Strict-Transport-Security'?: string; + TE?: string; + 'Timing-Allow-Origin'?: string; + Tk?: string; + Trailer?: string; + 'Transfer-Encoding'?: string; + 'Upgrade-Insecure-Requests'?: string; + 'User-Agent'?: string; + Vary?: string; + Via?: string; + 'WWW-Authenticate'?: string; + 'Want-Digest'?: string; + Warning?: string; + 'Content-Type-Options'?: string; + 'DNS-Prefetch-Control'?: string; + 'Forwarded-For'?: string; + 'Forwarded-Host'?: string; + 'Forwarded-Proto'?: string; + 'Frame-Options'?: string; + 'XSS-Protection'?: string; +}; + +export default AxiosHeaders; diff --git a/index.d.ts b/index.d.ts index fc1fd186af..4b98f927cd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,7 @@ +import AxiosHeaders from './headers'; + export interface AxiosTransformer { - (data: any, headers?: any): any; + (data: any, headers?: AxiosHeaders): any; } export interface AxiosAdapter { @@ -46,7 +48,7 @@ export interface AxiosRequestConfig { baseURL?: string; transformRequest?: AxiosTransformer | AxiosTransformer[]; transformResponse?: AxiosTransformer | AxiosTransformer[]; - headers?: any; + headers?: AxiosHeaders; params?: any; paramsSerializer?: (params: any) => string; data?: any; @@ -74,7 +76,7 @@ export interface AxiosResponse { data: T; status: number; statusText: string; - headers: any; + headers: AxiosHeaders; config: AxiosRequestConfig; request?: any; } From 56ee66ba842942f72a3fde8c6c99c5a6bd202d26 Mon Sep 17 00:00:00 2001 From: Keimeno Date: Thu, 9 Jan 2020 15:18:06 +0100 Subject: [PATCH 2/4] added quotes everywhere to get consistent autosuggestions --- headers.ts | 64 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/headers.ts b/headers.ts index 1a130f8ac0..c72eb42209 100644 --- a/headers.ts +++ b/headers.ts @@ -3,7 +3,7 @@ type LooseObject = object & { }; type AxiosHeaders = LooseObject & { - Accept?: string; + 'Accept'?: string; 'Accept-CH'?: string; 'Accept-CH-Lifetime'?: string; 'Accept-Charset'?: string; @@ -19,13 +19,13 @@ type AxiosHeaders = LooseObject & { 'Access-Control-Max-Age'?: string; 'Access-Control-Request-Headers'?: string; 'Access-Control-Request-Method'?: string; - Age?: string; - Allow?: string; + 'Age'?: string; + 'Allow'?: string; 'Alt-Svc'?: string; - Authorization?: string; + 'Authorization'?: string; 'Cache-Control'?: string; 'Clear-Site-Data'?: string; - Connection?: string; + 'Connection'?: string; 'Content-Disposition'?: string; 'Content-Encoding'?: string; 'Content-Language'?: string; @@ -35,64 +35,64 @@ type AxiosHeaders = LooseObject & { 'Content-Security-Policy'?: string; 'Content-Security-Policy-Report-Only'?: string; 'Content-Type'?: string; - Cookie?: string; - Cookie2?: string; + 'Cookie'?: string; + 'Cookie2'?: string; 'Cross-Origin-Resource-Policy'?: string; - DNT?: string; - DPR?: string; - Date?: string; + 'DNT'?: string; + 'DPR'?: string; + 'Date'?: string; 'Device-Memory'?: string; - Digest?: string; - ETag?: string; + 'Digest'?: string; + 'ETag'?: string; 'Early-Data'?: string; - Expect?: string; + 'Expect'?: string; 'Expect-CT'?: string; - Expires?: string; + 'Expires'?: string; 'Feature-Policy'?: string; - Forwarded?: string; - From?: string; - Host?: string; + 'Forwarded'?: string; + 'From'?: string; + 'Host'?: string; 'If-Match'?: string; 'If-Modified-Since'?: string; 'If-None-Match'?: string; 'If-Range'?: string; 'If-Unmodified-Since'?: string; - Index?: string; + 'Index'?: string; 'Keep-Alive'?: string; 'Large-Allocation'?: string; 'Last-Modified'?: string; - Link?: string; - Location?: string; - Origin?: string; - Pragma?: string; + 'Link'?: string; + 'Location'?: string; + 'Origin'?: string; + 'Pragma'?: string; 'Proxy-Authenticate'?: string; 'Proxy-Authorization'?: string; 'Public-Key-Pins'?: string; 'Public-Key-Pins-Report-Only'?: string; - Range?: string; - Referer?: string; + 'Range'?: string; + 'Referer'?: string; 'Referrer-Policy'?: string; 'Retry-After'?: string; 'Save-Data'?: string; 'Sec-WebSocket-Accept'?: string; - Server?: string; + 'Server'?: string; 'Server-Timing'?: string; 'Set-Cookie'?: string; 'Set-Cookie2'?: string; - SourceMap?: string; + 'SourceMap'?: string; 'Strict-Transport-Security'?: string; - TE?: string; + 'TE'?: string; 'Timing-Allow-Origin'?: string; - Tk?: string; - Trailer?: string; + 'Tk'?: string; + 'Trailer'?: string; 'Transfer-Encoding'?: string; 'Upgrade-Insecure-Requests'?: string; 'User-Agent'?: string; - Vary?: string; - Via?: string; + 'Vary'?: string; + 'Via'?: string; 'WWW-Authenticate'?: string; 'Want-Digest'?: string; - Warning?: string; + 'Warning'?: string; 'Content-Type-Options'?: string; 'DNS-Prefetch-Control'?: string; 'Forwarded-For'?: string; From 1ff67bee6df64263aff2a629a1cfffcc5b740780 Mon Sep 17 00:00:00 2001 From: Keimeno <58604248+Keimeno@users.noreply.github.com> Date: Wed, 15 Jan 2020 18:01:09 +0100 Subject: [PATCH 3/4] type of string, number and boolean can now be set for headers --- headers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headers.ts b/headers.ts index c72eb42209..d3abf89e2a 100644 --- a/headers.ts +++ b/headers.ts @@ -1,5 +1,5 @@ type LooseObject = object & { - [key: string]: string; + [key: string]: string | number | boolean; }; type AxiosHeaders = LooseObject & { From 531c5ec98646db06c708510f5fb154fd996933d7 Mon Sep 17 00:00:00 2001 From: Keimeno <58604248+Keimeno@users.noreply.github.com> Date: Thu, 23 Jan 2020 12:16:15 +0100 Subject: [PATCH 4/4] removed unnecessary object & --- headers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headers.ts b/headers.ts index d3abf89e2a..74a3fae5a7 100644 --- a/headers.ts +++ b/headers.ts @@ -1,4 +1,4 @@ -type LooseObject = object & { +type LooseObject = { [key: string]: string | number | boolean; };