A conditional type is a type-level expression that selects one of two possible types based on an assignability relationship. It evaluates whether a base type satisfies a specific constraint using theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
extends keyword. While its syntax mirrors the JavaScript ternary operator, its mechanics rely strictly on compile-time type assignability checks rather than runtime value truthiness.
Evaluation Mechanics
The core mechanism relies on theextends keyword acting as a subtyping or assignability check.
- If the type
Tis assignable to the typeU, the expression resolves to theTrueTypebranch. - If
Tis not assignable toU, it resolves to theFalseTypebranch.
T and U are fully known (instantiated) types, TypeScript evaluates the conditional type immediately. If T is an unresolved generic type parameter, the evaluation is deferred until the compiler possesses enough type information to resolve the assignability check.
Distributive Conditional Types
When a conditional type operates on a generic type parameter, and that parameter is a union type, the conditional type becomes distributive. This occurs exclusively when the type parameter is “naked”—meaning it is not wrapped within another type construct such as an array, tuple, or promise. During distribution, TypeScript maps the conditional operation across each constituent of the union type independently, and then unites the results.never. Because TypeScript treats never as an empty union, a distributive conditional type distributes zero times. The expression immediately resolves to never, bypassing the extends check entirely.
extends clause must be wrapped in a tuple. This forces the compiler to evaluate the union as a single, cohesive type rather than distributing over its constituents. It also prevents never from short-circuiting the evaluation.
Pattern Matching with infer
Conditional types support structural type extraction via the infer keyword. When used within the extends clause, infer introduces a declarative type variable that the compiler attempts to deduce based on the structure of the type being evaluated.
If the assignability check succeeds, the inferred type variable becomes available exclusively within the TrueType branch.
infer declarations can be utilized within a single conditional type to extract multiple structural components simultaneously, provided the base type matches the complex signature defined in the extends clause.
Master TypeScript with Deep Grasping Methodology!Learn More





