The Awaited type is a utility type where the data type that is returned from either await when using async functions or .then() when using promises is assigned to a type.

Structure

Awaited <Type>

Examples

type PromiseString = Promise<string>;

type AwaitedString = Awaited<PromiseString>; //type AwaitedString = string
type PromiseNumberBoolean = Promise<number|boolean>;

type AwaitedNumberBoolean = Awaited<PromiseNumberBoolean>; //type AwaitedNumberBoolean = number | boolean
type PromisePromiseNumber = Promise<Promise<number>>;

type AwaitedPromisePromiseNumber = Awaited<PromisePromiseNumber> //type AwaitedPromisePromiseNumber = numberAwaitedPromisePromiseNumber = number
async function getDepartment(): Promise<{id: number, name: string}> {
  return {id: 1, name: 'IT Department'}
}

type Department = Awaited<typeof getDepartment> /* type Department = () => Promise<{
                                                       id: number;
                                                       name: string;
                                                   }>*/