Challenge - 5 Problems
Template Literal Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Template Literal Type Concatenation
What is the type of variable
result after this code runs?Typescript
type Greeting = "Hello"; type Name = "Alice" | "Bob"; type Result = `${Greeting}, ${Name}!`; let result: Result; result = "Hello, Alice!";
Attempts:
2 left
💡 Hint
Think about how template literal types combine unions.
✗ Incorrect
The template literal type combines the union of Name with the fixed Greeting string, producing a union of all possible combinations.
❓ Predict Output
intermediate2:00remaining
Result of Nested Template Literal Types
What is the type of
fullId after this code?Typescript
type Prefix = "ID" | "UID"; type NumberStr = `${number}`; type FullId = `${Prefix}-${NumberStr}`; let fullId: FullId; fullId = "UID-123";
Attempts:
2 left
💡 Hint
Remember that `${number}` becomes string but is still a template literal type.
✗ Incorrect
The type FullId is a template literal combining Prefix union and a string representation of a number, so it is `${"ID" | "UID"}-${string}`.
🔧 Debug
advanced2:00remaining
Identify the Error in Template Literal Type Usage
What error does this TypeScript code produce?
Typescript
type Color = "red" | "blue"; type Shade = "light" | "dark"; type ColoredShade = `${Shade} ${Color}`; let paint: ColoredShade = "bright red";
Attempts:
2 left
💡 Hint
Check if the assigned string matches the template literal type exactly.
✗ Incorrect
The string "bright red" is not part of the union generated by `${Shade} ${Color}`, which only includes "light red", "light blue", "dark red", and "dark blue".
🧠 Conceptual
advanced2:00remaining
Understanding Template Literal Type Distributive Behavior
Given
type A = "x" | "y" and type B = `${A}1`, what is the expanded type of B?Attempts:
2 left
💡 Hint
Template literal types distribute over unions.
✗ Incorrect
The template literal type applies to each member of the union separately, producing "x1" and "y1" as the union members.
❓ Predict Output
expert3:00remaining
Complex Template Literal Type with Conditional Types
What is the type of
Result after this code?Typescript
type Status = "success" | "error"; type Message<T extends Status> = T extends "success" ? `Operation was ${T}` : `Operation failed with ${T}`; type Result = Message<Status>;
Attempts:
2 left
💡 Hint
Conditional types distribute over unions.
✗ Incorrect
The conditional type applies to each member of Status, producing a union of the two template literal strings.