When working on my project's type declaration file, I encountered a dilemma with using Axios types as part of my own types. The issue lies in the fact that all declarations for Axios are exported from their official repository.
I specifically need to incorporate AxiosResponse
and AxiosError
in my declaration file, but there isn't a separate set of @types
available for Axios. Even with meticulous configuration in my tsconfig.json
, the compiler doesn't automatically recognize these types due to the exhaustive export nature of the Axios declaration file.
Below is a snippet of my tsconfig:
{
"compilerOptions": {
"target": "es2017",
"outDir": "dist/main",
"rootDir": "src",
"moduleResolution": "node",
"module": "commonjs",
"declaration": true,
"inlineSourceMap": true,
"esModuleInterop": true,
...
"lib": ["es2017"],
"types": ["axios"],
"typeRoots": ["node_modules/@types", "types", "node_modules"]
},
"include": [
"src/**/*"
],
"exclude": [
"./test/**/*"
]
}
The main goal here is to have access to Axios interfaces for accurate type validation within my codebase.