Skip to content

Exported classes in type definition are not actually exported #5031

Closed

Description

@wai-ti8m

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

Activity

  1. wai-ti8m commented on Oct 7, 2022

    @wai-ti8m
    Author

    I guess that's a duplicate of #5004

  2. wai-ti8m commented on Oct 7, 2022

    @wai-ti8m
    Author

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

  3. Carsten-Leue commented on Oct 7, 2022

    @Carsten-Leue

    +1 I am getting this error with 1.1.2

    export 'AxiosError' (imported as 'AxiosError') was not found in 'axios' (possible exports: default)
    
  4. abriginets commented on Oct 8, 2022

    @abriginets

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

  5. chrisweb commented on Oct 8, 2022

    @chrisweb

    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

  6. Carsten-Leue commented on Oct 9, 2022

    @Carsten-Leue

    Another workaround is the use of 'axios.isAxiosError'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions