TS] generic..?

Bewell·2022년 1월 6일
0

@nuxt.js/composition-apiuseAsync 타입이다

const useAsync: <T>(cb: () => T | Promise<T>, key?: string | Ref<null> | undefined) => Ref<T | null>)

export interface TrAmtSeries {
  trAmount: number
  timestamp: string
}

export interface ResponseData {
  trAmtSeries: TrAmtSeries[]
}

const [series1, seriesLast1] = await Promise.all([
  useAsync<ResponseData>(() => $axios.$get('/api/v1/dashboard/transaction/series', {
    method: 'get',
    params
  })),
  useAsync(() => $axios('/api/v1/dashboard/transaction/series/last', {
    method: 'get',
    params
  }))
])

series1 에는 ResponseData 제네릭을 넣었고, seriesLast1에는 제네릭을 넣지 않았다.

위 이미지와 같이 제네릭에 넣고 안넣고에 따라서 return 값이 아예 다르다.
아직은 이해하지 못하겠지만, 우선 기록해 놓는다

0개의 댓글