From efcf92ce6f92df0d1e2bd459729a3b6260288599 Mon Sep 17 00:00:00 2001 From: DigitalBrainJS Date: Tue, 3 May 2022 20:53:26 +0300 Subject: [PATCH] Added generic TS types for the exposed `toFormData` helper; --- index.d.ts | 5 +++++ test/typescript/axios.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/index.d.ts b/index.d.ts index d984f1d4ca..3f1b4901c1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; @@ -248,6 +252,7 @@ export interface AxiosStatic extends AxiosInstance { all(values: Array>): Promise; spread(callback: (...args: T[]) => R): (array: T[]) => R; isAxiosError(payload: any): payload is AxiosError; + toFormData(sourceObj: object, targetFormData?: GenericFormData): GenericFormData; } declare const axios: AxiosStatic; diff --git a/test/typescript/axios.ts b/test/typescript/axios.ts index 16780f7cea..aa8c80dd0d 100644 --- a/test/typescript/axios.ts +++ b/test/typescript/axios.ts @@ -371,3 +371,7 @@ axios.get('/user') const axiosError: AxiosError = error; } }); + +// FormData + +axios.toFormData({x: 1}, new FormData());