#How to do type determination for respons in Axios response interceptor

6 messages · Page 1 of 1 (latest)

zinc spire
robust flame
#

!screenshot

unique mantleBOT
#
`!screenshot`:

Rather than screenshots, please provide either code formatted as:

```ts
// code here
```
Or even better, as an example on the TypeScript playground that is as simple as possible and reproduces the issue. This makes it easier to help you and increases the chances of getting an answer.

robust flame
#

the axios methods can take a generic

#

this way, you can provide the type for the data returned by axios

unique mantleBOT
#
Ascor8522#7606

Preview:```ts
import axios from "axios"

interface MyAPIResponse {
foo: "foo"
bar: {
baz: true
}
}

await axios
.get<MyAPIResponse>("/api")
.then(data => data.data)
.then(data => {
console.log(data.bar.baz) // true
})```