Bird
Raised Fist0
Typescriptprogramming~20 mins

Capitalize and Uncapitalize types in Typescript - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Capitalize and Uncapitalize Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Capitalize type example?
Consider the following TypeScript code using the Capitalize utility type. What is the type of Result?
Typescript
type Result = Capitalize<'hello world'>;

// What is the type of Result?
A"hello world"
B"Hello World"
C"Hello world"
D"HELLO WORLD"
Attempts:
2 left
💡 Hint
Capitalize only changes the first character to uppercase, leaving the rest unchanged.
❓ Predict Output
intermediate
2:00remaining
What is the output of this Uncapitalize type example?
Look at this TypeScript code using the Uncapitalize utility type. What is the type of Result?
Typescript
type Result = Uncapitalize<'Hello World'>;

// What is the type of Result?
A"hello World"
B"hello world"
C"Hello World"
D"HELLO WORLD"
Attempts:
2 left
💡 Hint
Uncapitalize only changes the first character to lowercase, leaving the rest unchanged.
🧠 Conceptual
advanced
2:00remaining
Which option correctly describes Capitalize and Uncapitalize behavior?
Which statement correctly describes how the TypeScript utility types Capitalize and Uncapitalize work?
ACapitalize changes the first character to uppercase and all others to lowercase; Uncapitalize changes the first character to lowercase and all others to uppercase.
BCapitalize changes all characters to uppercase; Uncapitalize changes all characters to lowercase.
CCapitalize and Uncapitalize only work on number types, not strings.
DCapitalize changes the first character to uppercase; Uncapitalize changes the first character to lowercase; both leave the rest of the string unchanged.
Attempts:
2 left
💡 Hint
Think about how only the first letter is affected.
❓ Predict Output
advanced
2:00remaining
What is the type of Result after nested Capitalize and Uncapitalize?
Given this TypeScript code, what is the type of Result?
Typescript
type Result = Uncapitalize<Capitalize<'tYPEScript'>>;

// What is Result?
A"typeScript"
B"tYPEScript"
C"TypeScript"
D"TYPEScript"
Attempts:
2 left
💡 Hint
Apply Capitalize first, then Uncapitalize on the result.
❓ Predict Output
expert
3:00remaining
What is the output of this mapped type using Capitalize and Uncapitalize?
Consider this TypeScript code that uses mapped types with Capitalize and Uncapitalize. What is the resulting type of NewObj?
Typescript
type Original = {
  firstName: string;
  lastName: string;
  Age: number;
};

type NewObj = {
  [K in keyof Original as Capitalize<Uncapitalize<string & K>>]: Original[K]
};
A{ FirstName: string; LastName: string; Age: number; }
B{ Firstname: string; Lastname: string; Age: number; }
C{ firstname: string; lastname: string; age: number; }
D{ firstName: string; lastName: string; Age: number; }
Attempts:
2 left
💡 Hint
Uncapitalize then Capitalize on the key name affects only the first letter casing.

Practice

(1/5)
1. What does the Capitalize<T> utility type do in TypeScript?
easy
A. It makes the first letter of a string type lowercase.
B. It makes the entire string type uppercase.
C. It reverses the string type.
D. It makes the first letter of a string type uppercase.

Solution

  1. Step 1: Understand the purpose of Capitalize<T>

    The Capitalize utility type changes only the first letter of a string type to uppercase.
  2. Step 2: Compare with other options

    Other options describe different transformations like full uppercase or lowercase, which are not what Capitalize does.
  3. Final Answer:

    It makes the first letter of a string type uppercase. -> Option D
  4. Quick Check:

    Capitalize = first letter uppercase [OK]
Hint: Capitalize only changes the first letter to uppercase [OK]
Common Mistakes:
  • Thinking it changes the whole string to uppercase
  • Confusing Capitalize with Uncapitalize
  • Assuming it reverses the string
2. Which of the following is the correct syntax to uncapitalize a string type T in TypeScript?
easy
A. Uncapitalize<T>
B. Uncapitalize[T]
C. uncapitalize<T>
D. Uncapitalize(T)

Solution

  1. Step 1: Recall TypeScript generic syntax

    Generic utility types use angle brackets <> to specify the type parameter, like Uncapitalize<T>.
  2. Step 2: Check case sensitivity and brackets

    TypeScript is case sensitive and uses angle brackets, so 'Uncapitalize<T>' is correct, while parentheses or square brackets are invalid here.
  3. Final Answer:

    Uncapitalize<T> -> Option A
  4. Quick Check:

    Generic types use <> brackets [OK]
Hint: Use angle brackets for generic types like Uncapitalize<T> [OK]
Common Mistakes:
  • Using parentheses instead of angle brackets
  • Writing utility type names in lowercase
  • Using square brackets instead of angle brackets
3. What is the resulting type of Capitalize<'hello world'> in TypeScript?
medium
A. 'Hello world'
B. 'hello world'
C. 'HELLO WORLD'
D. 'hELLO WORLD'

Solution

  1. Step 1: Apply Capitalize to the string literal

    Capitalize changes only the first letter to uppercase, so 'hello world' becomes 'Hello world'.
  2. Step 2: Confirm the rest of the string remains unchanged

    Only the first character changes; the rest stays lowercase as in the original string.
  3. Final Answer:

    'Hello world' -> Option A
  4. Quick Check:

    Capitalize<'hello world'> = 'Hello world' [OK]
Hint: Only first letter changes to uppercase, rest stays same [OK]
Common Mistakes:
  • Making the entire string uppercase
  • Not changing any letter
  • Changing only the first letter to lowercase
4. Given the code snippet:
type T = uncapitalize<'HelloWorld'>;

What is the error in this code?
medium
A. The string literal should be lowercase.
B. The utility type name should be capitalized as Uncapitalize.
C. The angle brackets should be replaced with parentheses.
D. There is no error; the code is correct.

Solution

  1. Step 1: Check utility type name casing

    TypeScript utility types like Uncapitalize must start with uppercase letters; 'uncapitalize' is invalid.
  2. Step 2: Verify other syntax elements

    The string literal and angle brackets are correct; only the utility type name casing is wrong.
  3. Final Answer:

    The utility type name should be capitalized as Uncapitalize. -> Option B
  4. Quick Check:

    Utility types start with uppercase letters [OK]
Hint: Utility types always start with uppercase letters [OK]
Common Mistakes:
  • Using lowercase for utility type names
  • Changing brackets to parentheses
  • Thinking string literal case matters here
5. How can you create a new type that capitalizes the first letter of each word in a union type 'apple' | 'banana' | 'cherry' using TypeScript's Capitalize utility?
hard
A. type Fruits = Capitalize<'apple banana cherry'>;
B. type Fruits = Capitalize<apple | banana | cherry>;
C. type Fruits = Capitalize<'apple'> | Capitalize<'banana'> | Capitalize<'cherry'>;
D. type Fruits = Uncapitalize<'apple' | 'banana' | 'cherry'>;

Solution

  1. Step 1: Understand Capitalize on union types

    Capitalizing a union type like 'apple' | 'banana' | 'cherry' directly does not capitalize each word separately.
  2. Step 2: Capitalize each string literal individually

    Applying Capitalize to each string separately and then unioning them ensures each word's first letter is capitalized.
  3. Final Answer:

    type Fruits = Capitalize<'apple'> | Capitalize<'banana'> | Capitalize<'cherry'>; -> Option C
  4. Quick Check:

    Capitalize each union member separately [OK]
Hint: Capitalize each union member separately for correct result [OK]
Common Mistakes:
  • Applying Capitalize to the whole union at once
  • Using Uncapitalize instead of Capitalize
  • Trying to capitalize a single string with all words
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard