const fetcher = Axios.create()
fetcher.interceptors.response.use(config=>{
return config.data
})
Type of fetcher.get('...')
is AxiosInstance, but it's actually AxiosInstance.data type
So how could I change the type correctly?
It is not necessary to redefine the module.
Assuming your interceptor does response => response.data
and a server response like:
{
book: { id: 42 }
}
This should be enough:
type Book = {
id: number
}
type ResponseContainer = {
book: Book
}
request.post<unknown, ResponseContainer>('/api')
.then(({ book }) => console.log(book.id))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With