DEV Community

Discussion on: You Don't Need Axios

 
joshuaamaju profile image
Joshua Amaju • Edited

await axios.post<EventType[] | { errorMessage: string }>(urlApiCmdPublic, cmd) only works for non-error responses.

Fetch in comparison does not have any types at all

Not exactly true, you get aResponse which makes sense. And then you can convert to json and do validation i.e using zod schema.parse(await response.json()) to get a concrete type. Which is a much better approach than what axios offers

Some comments have been hidden by the post's author - find out more