Skip to content

Commit

Permalink
fix(types): fix AxiosHeaders types; (#5931)
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed Sep 29, 2023
1 parent 2ac731d commit a1c8ad0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions index.d.cts
Expand Up @@ -8,6 +8,8 @@ type MethodsHeaders = Partial<{

type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;

type AxiosHeaderParser = (this: AxiosHeaders, value: axios.AxiosHeaderValue, header: string) => any;

type CommonRequestHeadersList = 'Accept' | 'Content-Length' | 'User-Agent'| 'Content-Encoding' | 'Authorization';

type ContentType = axios.AxiosHeaderValue | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream';
Expand All @@ -16,18 +18,18 @@ type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' |

declare class AxiosHeaders {
constructor(
headers?: RawAxiosHeaders | AxiosHeaders
headers?: RawAxiosHeaders | AxiosHeaders | string
);

[key: string]: any;

set(headerName?: string, value?: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;

get(headerName: string, parser: RegExp): RegExpExecArray | null;
get(headerName: string, matcher?: true | AxiosHeaderMatcher): axios.AxiosHeaderValue;
get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;

has(header: string, matcher?: true | AxiosHeaderMatcher): boolean;
has(header: string, matcher?: AxiosHeaderMatcher): boolean;

delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;

Expand Down
12 changes: 7 additions & 5 deletions index.d.ts
Expand Up @@ -9,22 +9,24 @@ type MethodsHeaders = Partial<{
[Key in Method as Lowercase<Key>]: AxiosHeaders;
} & {common: AxiosHeaders}>;

type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
type AxiosHeaderMatcher = string | RegExp | ((this: AxiosHeaders, value: string, name: string) => boolean);

type AxiosHeaderParser = (this: AxiosHeaders, value: AxiosHeaderValue, header: string) => any;

export class AxiosHeaders {
constructor(
headers?: RawAxiosHeaders | AxiosHeaders
headers?: RawAxiosHeaders | AxiosHeaders | string
);

[key: string]: any;

set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;

get(headerName: string, parser: RegExp): RegExpExecArray | null;
get(headerName: string, matcher?: true | AxiosHeaderMatcher): AxiosHeaderValue;
get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;

has(header: string, matcher?: true | AxiosHeaderMatcher): boolean;
has(header: string, matcher?: AxiosHeaderMatcher): boolean;

delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;

Expand Down

0 comments on commit a1c8ad0

Please sign in to comment.