0
0
Typescriptprogramming~10 mins

Capitalize and Uncapitalize types in Typescript - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Capitalize and Uncapitalize types
Start with string type
Apply Capitalize<T>
First letter uppercase
Resulting type
Start with string type
Apply Uncapitalize<T>
First letter lowercase
Resulting type
Capitalize<T> makes the first letter uppercase; Uncapitalize<T> makes the first letter lowercase of a string type.
Execution Sample
Typescript
type Cap = Capitalize<'hello'>;
type Uncap = Uncapitalize<'WORLD'>;
This code creates two types: one with first letter capitalized, one with first letter uncapitalized.
Execution Table
StepType OperationInput TypeResult Type
1Capitalize<'hello'>'hello''Hello'
2Uncapitalize<'WORLD'>'WORLD''wORLD'
3Capitalize<'typescript'>'typescript''Typescript'
4Uncapitalize<'TypeScript'>'TypeScript''typeScript'
5Capitalize<'123abc'>'123abc''123abc' (unchanged, no letter)
6Uncapitalize<'ABC123'>'ABC123''aBC123'
ExitNo more operations--
💡 All examples processed, showing how first letter changes or stays if not a letter.
Variable Tracker
Type AliasInitial InputAfter OperationFinal Result
Cap'hello'Capitalize applied'Hello'
Uncap'WORLD'Uncapitalize applied'wORLD'
Key Moments - 2 Insights
Why does Capitalize<'123abc'> not change the string?
Because Capitalize only changes the first letter if it is a letter; digits stay the same as shown in execution_table row 5.
Does Uncapitalize change all letters or just the first one?
Only the first letter is changed to lowercase, the rest remain unchanged, as seen in execution_table rows 2 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of Capitalize<'hello'> at step 1?
A'hello'
B'HELLO'
C'Hello'
D'hELLO'
💡 Hint
Check the Result Type column at step 1 in the execution_table.
At which step does Uncapitalize change 'WORLD' to 'wORLD'?
AStep 2
BStep 5
CStep 3
DStep 4
💡 Hint
Look at the Type Operation and Result Type columns in execution_table.
If you apply Capitalize to 'typescript', what will be the result?
A'typescript'
B'Typescript'
C'TYPESCRIPT'
D'tYPESCRIPT'
💡 Hint
Refer to step 3 in execution_table for Capitalize<'typescript'>.
Concept Snapshot
Capitalize<T>: changes first letter of string type T to uppercase.
Uncapitalize<T>: changes first letter of string type T to lowercase.
Only affects first character if it is a letter.
Useful for transforming string literal types.
Syntax: type NewType = Capitalize<'string'> or Uncapitalize<'STRING'>.
Full Transcript
This visual execution shows how TypeScript's Capitalize and Uncapitalize types work. Capitalize takes a string type and makes its first letter uppercase, while Uncapitalize makes the first letter lowercase. For example, Capitalize<'hello'> becomes 'Hello', and Uncapitalize<'WORLD'> becomes 'wORLD'. If the first character is not a letter, like a digit, Capitalize does not change it. Only the first letter is affected; the rest of the string stays the same. This helps when you want to transform string literal types in your code. The execution table traces each step with input and output types, and the variable tracker shows how type aliases change. The quiz tests understanding of these transformations.