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?✗ Incorrect
Capitalize changes only the first letter to uppercase, so "typescript" becomes "Typescript".What is the result of
Uncapitalize<"Hello">?✗ Incorrect
Uncapitalize converts the first letter to lowercase, so "Hello" becomes "hello".Which of these types can
Capitalize be applied to?✗ 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 ""?✗ 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?
✗ 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.