-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Currently, we are modifying the global AxiosRequestConfig to add in apiVersion and versioningStrategy as optional properties. This is needed so TypeScript users can pass in those options on a request without getting any issues.
It would be better to find a different way to provide the same type safety without modifying the global AxiosRequestConfig.
What I can think of is creating our own type AxiosRequestConfigWithVersioning and exposing it. Then, recreate the axios interface with get, post, etc, to accept the AxiosRequestConfigWithVersioning instead of AxiosRequestConfig.
This also tightens things up in terms of type safety because as soon as you import this module then it automatically modifies AxiosRequestConfig. If a TypeScript user creates an axios instance that does not have versioning, they will still get the option to define apiVersion and versioningStrategy in the AxiosRequestConfig which could be confusing.
Reference:
axios-api-versioning/src/types.ts
Lines 37 to 46 in f680e77
| /** | |
| * modify the global axios type of AxiosRequestConfig | |
| * to add "apiVersion" & "versioningStrategy" to config object | |
| */ | |
| declare module "axios" { | |
| interface AxiosRequestConfig { | |
| apiVersion?: string; | |
| versioningStrategy?: string | |
| } | |
| } |