bezkoder/react-axios-typescript-example

Upgrading to Axios 0.23.0 Results in Object is of type 'unknown'. ts(2571) on add-tutorial.component.tsx

mjcarrabine opened this issue ยท 1 comments

Thank you for providing this github repository for the tutorial as it was invaluable identifying the issue.

The code works with axios version 0.21.1 specified in package.json in this repsitory. ๐Ÿ‘
The code still works if you upgrade to axios version 0.22.0 ๐Ÿ‘

However, there is a breaking change in axios version 0.23.0 ๐Ÿ‘Ž that results in an error in add-tutorial.component.tsx
image

I will try to resolve the issue on my own and update this issue, but I am still new at this.

Axios Release 0.23.0 includes breaking change Change never type to unknown #4142 which requires that the data type be specified when making calls to the Axios client.

Note: As per this comment Revert #3002 - set type of data to any #4141, it looks like this change will be reversed in a future version of Axios.

Updating tutorial.service.ts as shown below resolved this issue. More types may need to be specified, but this at least let it build and run.
image