Skip to content

Find another way to expose apiVersion and versioningStrategy inside AxiosRequestConfig #5

@Weffe

Description

@Weffe

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:

/**
* modify the global axios type of AxiosRequestConfig
* to add "apiVersion" & "versioningStrategy" to config object
*/
declare module "axios" {
interface AxiosRequestConfig {
apiVersion?: string;
versioningStrategy?: string
}
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions