The Capitalize type changes the first character of a string type to uppercase, leaving the rest unchanged.
Click to reveal answer
beginner
What is the purpose of the Uncapitalize type in TypeScript?
The Uncapitalize type changes the first character of a string type to lowercase, leaving the rest unchanged.
Click to reveal answer
beginner
How would you capitalize the string literal type "hello" using TypeScript's utility types?
You can use Capitalize<"hello"> which results in the type "Hello".
Click to reveal answer
beginner
Given the type type Lower = Uncapitalize<"World">;, what is the resulting type?
The resulting type is "world", where the first letter is converted to lowercase.
Click to reveal answer
intermediate
Can Capitalize and Uncapitalize be used with general string types (like string)?
No, they only work with string literal types or unions of string literals, not with the general string type.
Click to reveal answer
What does Capitalize<"typescript"> evaluate to?
A"Typescript"
B"typescript"
C"TYPESCRIPT"
D"tYpescript"
✗ Incorrect
Capitalize changes only the first letter to uppercase, so "typescript" becomes "Typescript".
What is the result of Uncapitalize<"Hello">?
A"Hello"
B"hello"
C"HELLO"
D"hELLO"
✗ Incorrect
Uncapitalize converts the first letter to lowercase, so "Hello" becomes "hello".
Which of these types can Capitalize be applied to?
AGeneral <code>string</code> type
BNumber types
CString literal types
DBoolean types
✗ Incorrect
Capitalize works only on string literal types, not on general string or other types.
What happens if you apply Capitalize to an empty string literal ""?
AIt returns <code>"undefined"</code>
BIt throws a compile error
CIt returns <code>" "</code> (space)
DIt returns <code>""</code> (empty string)
✗ Incorrect
Applying Capitalize to an empty string returns the empty string unchanged.
Which utility type would you use to make the first letter of a string lowercase?
AUncapitalize
BCapitalize
CUppercase
DLowercase
✗ Incorrect
Uncapitalize converts the first letter of a string literal to lowercase.
Explain how the Capitalize and Uncapitalize types work in TypeScript and give an example of each.
Think about how these types transform the first character of a string.
You got /4 concepts.
Describe a situation where using Capitalize or Uncapitalize types would be helpful in a TypeScript project.
Consider when you want to enforce or transform string formats in types.
You got /4 concepts.
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
Step 1: Understand the purpose of Capitalize<T>
The Capitalize utility type changes only the first letter of a string type to uppercase.
Step 2: Compare with other options
Other options describe different transformations like full uppercase or lowercase, which are not what Capitalize does.
Final Answer:
It makes the first letter of a string type uppercase. -> Option D
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
Step 1: Recall TypeScript generic syntax
Generic utility types use angle brackets <> to specify the type parameter, like Uncapitalize<T>.
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.
Final Answer:
Uncapitalize<T> -> Option A
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
Step 1: Apply Capitalize to the string literal
Capitalize changes only the first letter to uppercase, so 'hello world' becomes 'Hello world'.
Step 2: Confirm the rest of the string remains unchanged
Only the first character changes; the rest stays lowercase as in the original string.
Final Answer:
'Hello world' -> Option A
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
Step 1: Check utility type name casing
TypeScript utility types like Uncapitalize must start with uppercase letters; 'uncapitalize' is invalid.
Step 2: Verify other syntax elements
The string literal and angle brackets are correct; only the utility type name casing is wrong.
Final Answer:
The utility type name should be capitalized as Uncapitalize. -> Option B
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
Step 1: Understand Capitalize on union types
Capitalizing a union type like 'apple' | 'banana' | 'cherry' directly does not capitalize each word separately.
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.
Final Answer:
type Fruits = Capitalize<'apple'> | Capitalize<'banana'> | Capitalize<'cherry'>; -> Option C
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 unknownstrongwhile earning +1 Grip toward your certificate.