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

Match ES2022 Error cause property on AxiosError #5849

Open
ericdowell opened this issue Aug 31, 2023 · 1 comment · May be fixed by #5850
Open

Match ES2022 Error cause property on AxiosError #5849

ericdowell opened this issue Aug 31, 2023 · 1 comment · May be fixed by #5850
Labels
priority::medium A medium priority

Comments

@ericdowell
Copy link

ericdowell commented Aug 31, 2023

Describe the bug

When trying to assign AxiosError.cause to unknown I get the following error, which does not happen with a normal Error class.

TS2739: Type  {}  is missing the following properties from type  Error :  name, message 

To Reproduce

Passing in ErrorOptions to a helper function we can recreate the issue. Currently I will need to add // @ts-ignore to get around this issue.

Code snippet

export const setCauseError = (
  error: AxiosError,
  options?: ErrorOptions
): Error => {
  if (options?.cause) {
    error.cause = options.cause
  }
  return error
}

Expected behavior

No TS error should be emitted to my IDE/type checking.

Axios Version

1.5.0

Adapter Version

n/a

Browser

n/a

Browser Version

n/a

Node.js Version

18.16.0

OS

macOS 13.5.1

Additional Library Versions

typescript 5.1.6

Additional context/Screenshots

With Error:

Screenshot 2023-08-31 at 1 37 08 PM

With unknown:

Screenshot 2023-08-31 at 1 37 39 PM
@ericdowell
Copy link
Author

@jasonsaayman Are you or another member that maintains this package to take a look at the PR I've opened? #5850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority::medium A medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants