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 Pattern | infer Expression | Inferred Result |
|---|---|---|
| Return Type | T extends (...args: any[]) => infer R ? R : any | Function return type |
| Parameters | T extends (...args: infer P) => any ? P : any | Function parameter tuple |
| Promise Inner | T extends Promise ? U : T | Resolved promise value |
T extends (infer E)[] ? E : T | Array element type |