type-challenges / type-challenges

Collection of TypeScript type challenges with online judge
https://tsch.js.org/
MIT License
42.73k stars 4.65k forks source link

189 - Awaited #32897

Open YJCCreateAHistory opened 5 months ago

YJCCreateAHistory commented 5 months ago
type UnwrapPromise<T> = T extends Promise<infer R> ? UnwrapPromise<R> : T;
type MyAwaited<T> = T extends { then: (onfulfilled: (arg: infer R) => any) => any } ? UnwrapPromise<R> : never;
nickfox-cn commented 5 months ago
type MyAwaited<T extends PromiseLike<any>> = T extends PromiseLike<infer R> ?R extends PromiseLike<any> ?MyAwaited<R>:R:never