0
0
Typescriptprogramming~5 mins

Nested conditional types in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a nested conditional type in TypeScript?
A nested conditional type is a conditional type used inside another conditional type, allowing complex type decisions based on multiple conditions.
Click to reveal answer
intermediate
Explain the syntax of a nested conditional type.
It uses the form Condition1 ? (Condition2 ? TrueType2 : FalseType2) : FalseType1, where one conditional type is inside the true or false branch of another.
Click to reveal answer
beginner
Given T extends string ? (T extends "hello" ? 1 : 2) : 3, what is the type when T = "hello"?
The type is 1 because T extends string and also extends "hello".
Click to reveal answer
intermediate
Why use nested conditional types instead of multiple separate conditional types?
Nested conditional types allow combining multiple checks in one type expression, making type logic more concise and expressive.
Click to reveal answer
advanced
How do nested conditional types help with type inference?
They enable fine-grained type decisions based on multiple conditions, improving the accuracy of inferred types in complex scenarios.
Click to reveal answer
What does a nested conditional type allow you to do?
AMake type decisions based on multiple conditions inside one type
BWrite multiple unrelated types
COnly check one condition at a time
DCreate runtime if-else statements
In T extends string ? (T extends "a" ? 1 : 2) : 3, what is the result if T = number?
A3
B2
C1
DError
Which part of a nested conditional type can contain another conditional type?
AOnly the true branch
BEither the true or false branch
CNeither branch
DOnly the false branch
What is the main benefit of nested conditional types?
AImprove performance of JavaScript
BSimplify runtime code
CAllow complex compile-time type logic
DReplace interfaces
Which TypeScript feature is essential to use nested conditional types?
AModules
BEnums
CClasses
DGenerics
Describe how nested conditional types work and give a simple example.
Think about how one condition can be inside another.
You got /3 concepts.
    Explain why nested conditional types are useful in TypeScript type design.
    Consider how complex type decisions are made.
    You got /3 concepts.