0
0
Typescriptprogramming~20 mins

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

Choose your learning style9 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.