Google News
logo
TypeScript - Interview Questions
What are Conditional Types in TypeScript ?
Based on a condition given as a type relationship test, a conditional type chooses one of two alternative types :
 
T extends U ? X : Y
 
When T can be assigned to U, the type is X, and when it can't, the type is Y.
 
Because the condition depends on one or more type variables, a conditional type T extends U? X: Y and is either resolved to X or Y or delayed. Whether to resolve to X or Y, or to defer, when T or U contains type variables is determined by whether the type system has enough information to conclude that T is always assignable to U.
Advertisement