Skip to content

Commit

Permalink
Added generic TS types for the exposed toFormData helper; (#4668)
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalBrainJS committed May 3, 2022
1 parent e52af17 commit c07998a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.d.ts
Expand Up @@ -237,6 +237,10 @@ export interface AxiosInstance extends Axios {
(url: string, config?: AxiosRequestConfig): AxiosPromise;
}

export interface GenericFormData {
append(name: string, value: any, options?: any): any;
}

export interface AxiosStatic extends AxiosInstance {
create(config?: AxiosRequestConfig): AxiosInstance;
Cancel: CancelStatic;
Expand All @@ -248,6 +252,7 @@ export interface AxiosStatic extends AxiosInstance {
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;
toFormData(sourceObj: object, targetFormData?: GenericFormData): GenericFormData;
}

declare const axios: AxiosStatic;
Expand Down
4 changes: 4 additions & 0 deletions test/typescript/axios.ts
Expand Up @@ -371,3 +371,7 @@ axios.get('/user')
const axiosError: AxiosError = error;
}
});

// FormData

axios.toFormData({x: 1}, new FormData());

0 comments on commit c07998a

Please sign in to comment.