ReviseAlgo Logo

Advanced Types

Conditional Types — infer Keyword

Master the infer keyword in TypeScript conditional types, extracting return types, parameter types, promise inner types, and pattern matching.

Last Updated: July 29, 2026 10 min read

The infer keyword is used inside conditional type checks (extends) to declare a temporary type variable that TypeScript automatically infers from pattern matching against a target type.

1. Syntax for infer

2. Practical infer Examples

1. Extracting Function Return Types (ReturnType)

2. Extracting Unwrapped Promise Values (Awaited)

3. Extracting Array Element Types

3. Inferring Tuple First & Last Elements

4. Interactive Code Playground

Test the infer keyword below:

5. Summary Table

Utility Patterninfer ExpressionInferred Result
Return TypeT extends (...args: any[]) => infer R ? R : anyFunction return type
ParametersT extends (...args: infer P) => any ? P : anyFunction parameter tuple
Promise InnerT extends Promise ? U : TResolved promise value
| Array Item | T extends (infer E)[] ? E : T | Array element type |