#189Easy

Awaited

Unwrap Promise types recursively with TypeScript. Learn conditional types, infer keyword, and recursive types in this easy-level challenge on TypeScriptPro.

Unwrap nested Promises to get their resolved types! 🎁

In this easy-level challenge, you'll implement a type that extracts the value type from Promises, even when they're nested multiple levels deep. This is similar to TypeScript's built-in Awaited type and is essential for working with asynchronous code at the type level.

You'll learn about conditional types with infer, recursive type definitions, and how to handle Promise-like objects with then methods. This challenge bridges the gap between TypeScript's type system and JavaScript's asynchronous patterns.

For this challenge, you will need to change the following code to make the tests pass (no type check errors).

Challenge Instructions: Awaited

Easy

If we have a type which is a wrapped type like Promise, how can we get the type which is inside the wrapped type?

For example: if we have Promise<ExampleType> how to get ExampleType?

type ExampleType = Promise<string>
 
type Result = MyAwaited<ExampleType> // string

This question is ported from the original article by @maciejsikora

Loading...

Video Walkthrough

Detailed Explanation

To unwrap Promise types, we need to use conditional types with infer and handle recursion for nested Promises.

type MyAwaited<T> = T extends PromiseLike<infer Value> ? MyAwaited<Value> : T

How it works:

This handles all cases including Promise<string>, Promise<Promise<number>>, and custom thenable objects, making it a robust solution for async type unwrapping.

Share this challenge

Join early, learn faster.

Be the first to access the course, unlock exclusive launch bonuses, and get special early-bird pricing before anyone else.

No spam, unsubscribe at any time. We respect your privacy.

Limited Availability

Only 27 Spots left

Early Access

Get 1 month early access

>75% Off

Pre-Launch discount

This challenge is originally from here.