00189-easy-awaited
Easy
promise
built-in

チャレンジのソース: type-challenges/00189-easy-awaited

Promise ライクな型が内包する型をどのように取得すればよいでしょうか。

例えば:Promise<ExampleType>という型がある場合、どのようにして ExampleType を取得すればよいでしょうか。

type ExampleType = Promise<string>

type Result = MyAwaited<ExampleType> // string

この問題の元記事は original article by @maciejsikora です。

Loading...
import type { Equal, Expect } from '@type-challenges/utils'

type X = Promise<string>
type Y = Promise<{ field: number }>
type Z = Promise<Promise<string | number>>
type Z1 = Promise<Promise<Promise<string | boolean>>>
type T = { then: (onfulfilled: (arg: number) => any) => any }

type cases = [
  Expect<Equal<MyAwaited<X>, string>>,
  Expect<Equal<MyAwaited<Y>, { field: number }>>,
  Expect<Equal<MyAwaited<Z>, string | number>>,
  Expect<Equal<MyAwaited<Z1>, string | boolean>>,
  Expect<Equal<MyAwaited<T>, number>>,
]