mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Test types (#4140)
* Distinguish request and response data types * Fix Axios headers type `axios.headers` is not of the same type as `request.headers`, so a new type `AxiosDefaults` was introduced * Replace grunt-ts with dtslint This asserts that the type definitions are valid in the specified TypeScript version and above. This is the same tool that is used by DefinitelyTyped. * Remove grunt-ts * Restore typescript dependency * Fix missing semicolons Co-authored-by: Claas Augner <github@caugner.de> Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Vendored
+30
-10
@@ -1,8 +1,10 @@
|
||||
export type AxiosRequestHeaders = Record<string, string>
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
export type AxiosRequestHeaders = Record<string, string>;
|
||||
|
||||
export type AxiosResponseHeaders = Record<string, string> & {
|
||||
"set-cookie"?: string[]
|
||||
}
|
||||
};
|
||||
|
||||
export interface AxiosRequestTransformer {
|
||||
(data: any, headers?: AxiosRequestHeaders): any;
|
||||
@@ -26,7 +28,7 @@ export interface AxiosProxyConfig {
|
||||
port: number;
|
||||
auth?: {
|
||||
username: string;
|
||||
password:string;
|
||||
password: string;
|
||||
};
|
||||
protocol?: string;
|
||||
}
|
||||
@@ -41,7 +43,7 @@ export type Method =
|
||||
| 'patch' | 'PATCH'
|
||||
| 'purge' | 'PURGE'
|
||||
| 'link' | 'LINK'
|
||||
| 'unlink' | 'UNLINK'
|
||||
| 'unlink' | 'UNLINK';
|
||||
|
||||
export type ResponseType =
|
||||
| 'arraybuffer'
|
||||
@@ -49,9 +51,9 @@ export type ResponseType =
|
||||
| 'document'
|
||||
| 'json'
|
||||
| 'text'
|
||||
| 'stream'
|
||||
| 'stream';
|
||||
|
||||
export interface TransitionalOptions{
|
||||
export interface TransitionalOptions {
|
||||
silentJSONParsing?: boolean;
|
||||
forcedJSONParsing?: boolean;
|
||||
clarifyTimeoutError?: boolean;
|
||||
@@ -89,7 +91,25 @@ export interface AxiosRequestConfig<D = any> {
|
||||
decompress?: boolean;
|
||||
transitional?: TransitionalOptions;
|
||||
signal?: AbortSignal;
|
||||
insecureHTTPParser?: boolean
|
||||
insecureHTTPParser?: boolean;
|
||||
}
|
||||
|
||||
export interface HeadersDefaults {
|
||||
common: AxiosRequestHeaders;
|
||||
delete: AxiosRequestHeaders;
|
||||
get: AxiosRequestHeaders;
|
||||
head: AxiosRequestHeaders;
|
||||
post: AxiosRequestHeaders;
|
||||
put: AxiosRequestHeaders;
|
||||
patch: AxiosRequestHeaders;
|
||||
options?: AxiosRequestHeaders;
|
||||
purge?: AxiosRequestHeaders;
|
||||
link?: AxiosRequestHeaders;
|
||||
unlink?: AxiosRequestHeaders;
|
||||
}
|
||||
|
||||
export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||
headers: HeadersDefaults;
|
||||
}
|
||||
|
||||
export interface AxiosResponse<T = unknown, D = any> {
|
||||
@@ -148,13 +168,13 @@ export interface AxiosInterceptorManager<V> {
|
||||
|
||||
export class Axios {
|
||||
constructor(config?: AxiosRequestConfig);
|
||||
defaults: AxiosRequestConfig;
|
||||
defaults: AxiosDefaults;
|
||||
interceptors: {
|
||||
request: AxiosInterceptorManager<AxiosRequestConfig>;
|
||||
response: AxiosInterceptorManager<AxiosResponse>;
|
||||
};
|
||||
getUri(config?: AxiosRequestConfig): string;
|
||||
request<T = unknown, R = AxiosResponse<T>, D = any> (config: AxiosRequestConfig<D>): Promise<R>;
|
||||
request<T = unknown, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
||||
get<T = unknown, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
delete<T = unknown, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
head<T = unknown, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
||||
@@ -176,7 +196,7 @@ export interface AxiosStatic extends AxiosInstance {
|
||||
Axios: typeof Axios;
|
||||
readonly VERSION: string;
|
||||
isCancel(value: any): boolean;
|
||||
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
|
||||
all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
||||
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
||||
isAxiosError(payload: any): payload is AxiosError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user