Challenge - 5 Problems
Template Literal Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of Template Literal Type Combination
What is the type of
Result after this code runs?Typescript
type Colors = "red" | "blue"; type Shades = "light" | "dark"; type Result = `${Shades}-${Colors}`; // What is Result?
Attempts:
2 left
💡 Hint
Think about how template literal types combine each option from both unions.
✗ Incorrect
Template literal types create all combinations of the union members by concatenating them with the given pattern.
🧠 Conceptual
intermediate1:00remaining
Why Use Template Literal Types for String Manipulation?
Which of the following best explains why template literal types are powerful in TypeScript?
Attempts:
2 left
💡 Hint
Think about how template literal types help with type safety for strings.
✗ Incorrect
Template literal types let you build new string types from unions, so TypeScript can check if strings match expected patterns.
❓ Predict Output
advanced1:30remaining
Output of Nested Template Literal Types
What is the type of
Combined after this code?Typescript
type Prefix = "get" | "set"; type Entity = "User" | "Product"; type Combined = `${Prefix}${Entity}Info`; // What is Combined?
Attempts:
2 left
💡 Hint
Consider how each prefix combines with each entity and the fixed suffix.
✗ Incorrect
The template literal type creates all combinations of Prefix and Entity, then adds 'Info' at the end.
🔧 Debug
advanced1:00remaining
Identify the Error in Template Literal Type Usage
What error will this TypeScript code produce?
Typescript
type A = "foo" | "bar"; type B = `${A}`; // Missing closing backtick
Attempts:
2 left
💡 Hint
Check the syntax carefully for missing characters.
✗ Incorrect
The template literal type is missing the closing backtick, causing a syntax error.
🚀 Application
expert2:00remaining
Using Template Literal Types to Enforce API Endpoint Patterns
Given these types, which option correctly defines
ApiEndpoint to represent endpoints like '/user/123' or '/product/456' where the number is dynamic but must be a string literal type?Typescript
type Resource = "user" | "product"; type Id = `${number}`; // Define ApiEndpoint here
Attempts:
2 left
💡 Hint
Use template literal types with string literal unions and template types for numbers.
✗ Incorrect
Option A correctly uses a template literal type combining Resource and Id (which is a string literal of a number) to represent dynamic numeric IDs as strings.