# The Awaited Type

> Unwrapping Promises to their final resolved type.

Subject: TypeScript | Lesson 41 of 54 | 3 min read
Interactive lesson: https://codewithanimation.in/typescript/awaited-type
Previous: [Parameters & ReturnType](https://codewithanimation.in/typescript/parameters-and-returntype.md) | Next: [Classes & Visibility](https://codewithanimation.in/typescript/classes-and-visibility.md)

## Unwrapping Promises

The `Awaited<Type>` utility is meant to model operations like `await` in `async` functions, or the `.then()` method on Promises.

It recursively unwraps Promises until it finds the base, non-promise value.

## Extracting Async Results

If you are calling a function that returns a `Promise<User>`, you might want to extract the `User` type to use elsewhere in your app.

You can combine `Awaited` and `ReturnType` to grab the exact data type that the API call will eventually yield.

## Syntax

```typescript
async function fetchUser() {
  return { id: 1, name: "Alice" };
}

// 1. Get the return type (it's a Promise!)
type AsyncResult = ReturnType<typeof fetchUser>; 
// Promise<{ id: number, name: string }>

// 2. Unwrap the Promise using Awaited
type UserData = Awaited<AsyncResult>; 
// { id: number, name: string }
```

## Common mistake: Recursive Unwrapping

Sometimes you end up with weird types like `Promise<Promise<string>>` due to nested async generic logic.

The `Awaited` utility handles this gracefully. It is recursive! It will unwrap *all* layers of Promises until it hits `string`.

## Tip: Under the Hood

`Awaited` checks if the type has a `.then()` method (a "thenable"). If it does, it infers the argument passed to `.then()` and recursively calls `Awaited` on it!

## Try it: Try it

Watch how the `Awaited` utility recursively peels back layers of Promises until it reaches the core primitive type.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/typescript/awaited-type

## Check yourself

### Question 1

What is the result of `Awaited<Promise<Promise<number>>>`?

- A. Promise<number>
- B. number
- C. never

Correct answer: B

Awaited is recursive! It will continually unwrap layers of Promises until it reaches the base primitive or object type.

- Why not A: Awaited is recursive; it unwraps all layers.

## Remember this

- `Awaited<T>` extracts the type that a Promise resolves to.
- It is fully recursive, meaning it handles nested `Promise<Promise<T>>` automatically.
- It models the behavior of the `await` keyword at the type level.
- Often combined with `ReturnType` to extract the data type from an async API function.
