brunch

Type에서 Promise 제거하기

by brunchdev


Awaited로 타입을 씌워 주면 된다.

// A = string
type A = Awaited<Promise<string>>;


주의점은 겹쳐진 Promise를 모두 제거해준다는 점!

// B = number
type B = Awaited<Promise<Promise<number>>>;


참고

https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#awaited-type

https://stackoverflow.com/questions/48944552/typescript-how-to-unwrap-remove-promise-from-a-type


keyword
이전 08화NextJS Link 경고