Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exported classes in type definition are not actually exported #5031

Closed
wai-ti8m opened this issue Oct 6, 2022 · 6 comments · Fixed by #5162
Closed

Exported classes in type definition are not actually exported #5031

wai-ti8m opened this issue Oct 6, 2022 · 6 comments · Fixed by #5162

Comments

@wai-ti8m
Copy link

wai-ti8m commented Oct 6, 2022

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

@wai-ti8m
Copy link
Author

wai-ti8m commented Oct 7, 2022

I guess that's a duplicate of #5004

@wai-ti8m wai-ti8m closed this as completed Oct 7, 2022
@wai-ti8m
Copy link
Author

wai-ti8m commented Oct 7, 2022

Issue not fixed: Classes are still not exported in the index.js file. Need to add something like export * from './lib/axios.js';

@Carsten-Leue
Copy link

+1 I am getting this error with 1.1.2

export 'AxiosError' (imported as 'AxiosError') was not found in 'axios' (possible exports: default)

@abriginets
Copy link

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 ¯\_(ツ)_/¯

@chrisweb
Copy link

chrisweb commented Oct 8, 2022

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: #5062

@Carsten-Leue
Copy link

Another workaround is the use of 'axios.isAxiosError'

jasonsaayman added a commit that referenced this issue Oct 13, 2022
* chore: add necessary devDependencies for rollup build

* fix: keep top-level export same with static properties(#5031)

Co-authored-by: ronggui.shu <ronggui.shu@sci-inv.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants