I am using axios interceptors to customize the requests I send from my application. I am not using typescript and so I am documenting my code using JsDoc to help my futureself understand what some custom properties mean.
I have an axios Interceptor checking for a custom property added on the config object to help add Authorization header without much hassle:
const http = axios.create({});
http.interceptors.request.use(
async (config) => {
if (config?.includeAuthorization) {
config.withCredentials = true;
const Cookies = require("js-cookie"); // Using require since dynamic import(above) fails to import module
const token = Cookies.get(JWTAuthTokenName);
if (token) {
config.headers["Authorization"] = `Bearer ${token}`;
}
delete config.includeAuthorization;
}
return config;
},
function (error) {
return Promise.reject(error);
}
);
I have a custom property includeAuthorization added to request config. This is not part of axios request config but Nonetheless, I would like to document with JsDoc telling its type and an explanation of what it does. I do not know how to go about this.
I have tried the following at the top of my file(same file I've created Axios instance):
/**
* @typedef {import("axios").AxiosRequestConfig} axios
* @property {boolean} includeAuthorization - If `true`, Authorization header with value read from cookie is added to request
*
*/
But this requires me to use the type definition I have created(axios). If I have to use it, then I do not know where. I expected this to extend AxiosRequestConfig globally and include my custom propery(includeAuthorization). That did not happen.
I would highly appreciate your input on how I can get around this problem.