0
0
Typescriptprogramming~5 mins

Capitalize and Uncapitalize types in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Capitalize type do in TypeScript?
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"
What is the result of Uncapitalize<"Hello">?
A"Hello"
B"hello"
C"HELLO"
D"hELLO"
Which of these types can Capitalize be applied to?
AGeneral <code>string</code> type
BNumber types
CString literal types
DBoolean 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)
Which utility type would you use to make the first letter of a string lowercase?
AUncapitalize
BCapitalize
CUppercase
DLowercase
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.