axios
axios copied to clipboard
Exported classes in type definition are not actually exported
Describe the bug
AxiosHeaders
, AxiosError
, CanceledError
and Axios
are "exported" in the type definitions index.d.ts
, but not exported in the module.
To Reproduce
const { AxiosHeaders } = require('axios'); // Allowed by Typescript
const headers = new AxiosHeaders({ 'name': 'value' }); // <-- throws Error as AxiosHeaders is not actually exported
Expected behavior
~~Types are not exported, but only declared (declare class
instead of export class
).~~
Classes are exported and can be imported and used like so:
import { AxiosError, AxiosHeaders, Axios, CanceledError } from 'axios';
new AxiosError();
new AxiosHeaders();
new Axios();
new CanceledError();
Environment
- Axios Version 1.1.0
- Node.js Version 16.15.1
- OS: OSX 12.5
- Typescript 4.6.3 (any version)
- React 17
Additional context/Screenshots
none
I guess that's a duplicate of #5004
Issue not fixed: Classes are still not exported in the index.js
file. Need to add something like export * from './lib/axios.js';
+1 I am getting this error with 1.1.2
export 'AxiosError' (imported as 'AxiosError') was not found in 'axios' (possible exports: default)
Having the same issue with CanceledError
:
import { CanceledError } from 'axios';
console.log(CanceledError); // undefined
And error instanceof CanceledError
throws an error because undefined
is not an object ¯\_(ツ)_/¯
Others like AxiosProgressEvent seem to be fine
As a workaround for now I used axios.AxiosError, so for example:
if (error instanceof axios.AxiosError) {
got the idea from this ticket: https://github.com/axios/axios/issues/5062
Another workaround is the use of 'axios.isAxiosError'