UPDATE: After some investigation, it turns out the issue was not related to Axios or TypeScript but rather a strange IDE configuration problem. Starting fresh by recreating the environment and .idea folder solved the issue.
While working with Axios in TypeScript, using async/await can sometimes lead to incorrect type inference by TypeScript. For instance:
let res = await Axios.get<Case[]>('/stack');
console.log(res);
I anticipated the return type of res to be AxiosResponse<Case[]>. However, TypeScript actually infers the type as simply Case[]. By logging to console, it's confirmed that the response is indeed an AxiosResponse object with the data property being of type Case[].
The TypeScript compiler (and IDE) wrongly interpret the return type as just an Array of Case objects.
If promises are used instead of async/await, then the behavior is as expected (using .then and .finally).
UPDATE: Based on feedback stating this issue did not occur for others, I attempted to replicate the project setup, and surprisingly the problem didn't manifest:
However, the cause of the issue in the original project remains unknown. It's worth noting that this is not an IDE-specific problem, as it also occurs in VS Code. Despite trying to reset node_modules, package-lock, and node cache, as well as reinstalling everything, the problem persists. Both projects use the same versions of TypeScript and Axios.