Return data from an axios get request
if you check the types of the Axios get()
function, you'll see that it has this implementation:
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
https://github.com/axios/axios/blob/master/index.d.ts#L137
So the first type passed (T
) is the type of the data, not the type of the response. In your case, you'll have to implement it this way:
this.productAxios.get<Product, ProductResponse>
Your data is indeed in response.data
:)