TypeScript · Middle · Question 6 of 75
What does the conditional type T extends string ? 'text' : 'other' do?
- ✓Correct answer: Picks one of the types depending on whether
Tis assignable tostring - 2Checks at runtime whether the value is a string and throws an error
- 3Declares that
Tinherits from the built-inStringclass
Explanation
Conditional types are a type-level "ternary". Together with infer, they let you extract parts of types. Applied to a union, they distribute over each member (distributive conditional types).