Conditional Type Result
Predict Output Medium
Question
What does this code print?
Code
type IsString<T> = T extends string ? "yes" : "no";
type A = IsString<"hello">;
type B = IsString<42>;
const a: A = "yes";
const b: B = "no";
console.log(a, b);
Hint
Conditional type selects "yes" for string, "no" for number.
Explanation
IsString<"hello">: "hello" extends string is true, so A is "yes". IsString<42>: 42 extends string is false, so B is "no". The conditional type evaluates at compile time.
Related Resources
Related Lessons
- Conditional Types
Learn conditional types.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.