-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
axios-typescript exemple doen't work #238
Comments
@vcombey I don't see any problem with the implementation. The errors should not exists. I will first explain what the error is saying: The axios's default export is a function that can be called with a
This config CAN NOT BE null. In the implementation, at line number 30, we can see So why are you seeing this error. For that, we need to know the typescript version that you are using. I have tested it on typescript:
If you just want a solution, you can force a type cast as following - >(request && JSON.stringify(request), () => axios(request || {}), {
+ >(request && JSON.stringify(request), () => axios((request || {}) as any as AxiosRequestConfig), { Hope it helps |
Yeah, the code works fine, but depending on how strict you've configured Typescript and your eslint settings, you might get complaints because Axios does not accept So, the fix, is simply to tell Typescript that we know it will not be () => axios(request!), I made a PR to update the example with this tweak. 🙂 |
Ok, thanks verry much for the explanations and the solution. Indeed I had configured typescript with "strict: false" to make him happy with the current example |
I still get the same error mentioned on this issue. Any tips to fix this? |
@giovanniantonaccio Can you please provide the error output and the source code for the fetch method? |
@sudkumar I just coppied the exact same code from this example: https://github.com/zeit/swr/blob/master/examples/axios-typescript/libs/useRequest.ts And I get this error in
|
@giovanniantonaccio Looks like there IS an issue with the The type of A quick way to resolve this would be letting the typescript know that it's OKAY for config to be null in initialData which is OK for most of the cases. initialData: initialData && {
.
- config: request
+ config: request!
.
} Hope it helps. Please feel free to ask if there are any queries. |
Thanks @sudkumar, this solved the problem! |
after copied in my project the useRequest fonction from the axios-typescript exemple typescript give me this error.
/app/src/useRequest.tsx
Im using axios 0.19.1 and swr 0.1.16.
Im totaly new to this ecosystem, and those errors looks scary for me. what is the problem, is that a version problem ?
The text was updated successfully, but these errors were encountered: