ReturnType<T>
The utility type that gives the return type of a function type T.
In more detail
ReturnType<typeof processOrder> reads the result type from the function itself, so wrappers stay correct when it changes. It is defined with a conditional type and infer.
Related terms
- Parameters<T> — The utility type that gives a function type's parameter list as a tuple, such as [orderId: string, priority: boolean].
- Awaited<T> — The utility type that unwraps a promise type to the value it resolves to, repeating through nested promises and thenables.
- infer — A keyword used inside the extends part of a conditional type to capture part of a matched type in a new type variable.
- wrapper function — A function that calls another function, adding behaviour before or after it, such as timing, retries or logging.
Taught in
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript