Is the breaking change in the type definition of AxiosError as intended?
See original GitHub issueDescribe the bug
The definition of AxiosError
had been updated at v0.27.0.
It seems compatible with the previous code, but this changeset is not based on #4186.
In v0.26.1, AxiosError
defined as <T = any, D = any> extends Error
.
https://github.com/axios/axios/blob/v0.26.1/index.d.ts#L139
As a result, AxiosError
has a different type definition than AxiosPromise
or AxiosResponse
. The former <T=unknown>
, the latter <T=any>
. I think these inconsistent definitions are undesirable.
It seems to me that this breaking change is unintentional, isn’t it?
To Reproduce
if (axios.isAxiosError(e)) {
console.log(e.response.data.message)
}
Got an error on e.response.data
.
Object is of type ‘unknown’.ts(2571)
Expected behavior
No errors occur.
Environment
- Axios Version: 0.27.2
Issue Analytics
- State:
- Created a year ago
- Reactions:19
- Comments:11
Top Results From Across the Web
I Keep getting, 'Object is of type 'unknown'' error - Stack Overflow
But it complains about the 'data' variable, saying 'Object is of type 'unknown'. After doing some research they said I have to use...
Read more >axioserror object - You.com | The search engine you control.
You're defining the paypal url as '${PAYPAL_API}/v2/checkout/orders' ... axios/axiosIs the breaking change in the type definition of AxiosError as intended?
Read more >Release notes - n8n Documentation
Release date: 2022-10-14. Breaking changes. Please note that this version contains breaking changes to the Merge node. You can read more about them...
Read more >nekoya on Twitter: "Axiosのv0.27、恐らく予期しない型のbreaking ...
Is the breaking change in the type definition of AxiosError as intended? · Issue #4716 · axios/axios. Describe the bug The definition of...
Read more >TypeScript errors and how to fix them
Set the “target” property in your “tsconfig.json” file to “es5” or higher: ... You have to separate the argument list from the return...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The following seems to work with v0.27:
If this is intentional behaviour then what is the preferred way of handling these error responses? Currently I have an app that frequently accesses the response data/messages for error logging and error message displaying, like so: