Awaited is not being unwrapped to R with response object

  Kiến thức lập trình

I’m returning an AxiosResponse object from a call to axios.get in a generic function. That object has the shape:

interface AxiosResponse<T = any, D = any> {
  data: T;
  ...
}

The get call has this type:

get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;

I’m hours into digging for an answer to fix this error:

screen grab from IDE

I understand that the Awaited<R> type was added in 4.5. I understand from other answers that the Awaited type should be unwrapped to R (from the accepted answer on that question):

If the type T you are awaiting is a Promise<U> where U isn’t a Promise of any kind, then Awaited<T> is the same as U

How do I fix this?

MODS: if you close this for being “duplicate”, please don’t post links to answers about Swift, or unrelated questions. I have little faith in SO so I expect you to do it anyway with a completely irrelevant question as what I’m duplicating. Surprise me; I’ve spent a lot of hours searching and didn’t find any duplicates.

LEAVE A COMMENT