How can I effectively utilize axios interceptors with TypeScript?
import axios, { AxiosRequestConfig, AxiosInstance } from 'axios'
HTTP.interceptors.request.use((config: AxiosRequestConfig) => config)
For instance, when creating an axios instance, default configuration is set up:
const conf: AxiosRequestConfig = {
baseURL: process.env.VUE_APP_API_URL
}
const HTTP: AxiosInstance = axios.create(conf)
However, when attempting to use interceptors with customized headers:
HTTP.interceptors.request.use((config: AxiosRequestConfig) =>{
headers: {
'x-projectkey': 1234
}
})
The above approach does not produce the desired outcome:
Argument of type '(config: AxiosRequestConfig) => void' is not assignable to parameter of type '(value: AxiosRequestConfig) => AxiosRequestConfig | Promise<AxiosRequestConfig>'
As a newcomer to TypeScript, this issue has me puzzled.