String manipulation intrinsics
Concept and syntax
Uppercase and Lowercase transform a string type across its characters; Capitalize and Uncapitalize change the initial character. They are compiler intrinsics, not locale-sensitive runtime methods. The corresponding runtime value must be created separately.
Working example
Save each snippet separately as main.ts in a fresh directory with TypeScript 5.8.3. Compile with tsc --strict --target ES2022 --module commonjs --moduleDetection force --skipLibCheck --noEmitOnError main.ts and run accepted snippets with node main.js. Type aliases are erased; assignments and diagnostic checks demonstrate the type relations, not the printed output alone.
type Names=[Uppercase<"tea">,Lowercase<"TEA">,Capitalize<"tea">,Uncapitalize<"Tea">];const n:Names=["TEA","tea","Tea","tea"]; console.log(n.join(" "));Expected output:
TEA tea Tea teaCommon mistake
Intentionally invalid; compile separately and do not execute.
type Names=[Uppercase<"tea">,Lowercase<"TEA">,Capitalize<"tea">,Uncapitalize<"Tea">];const n:Names=["Tea","tea","Tea","tea"];Expected diagnostic: TS2322. Uppercase requires TEA, not Tea.
Practice and recap
Compare Capitalize<"hello world"> with Uppercase.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
String manipulation intrinsics — knowledge check
Check the type transformation, trace output, diagnose a rejected example, and apply the concept to a new case.
Which statement about String manipulation intrinsics is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
type Names=[Uppercase<"tea">,Lowercase<"TEA">,Capitalize<"tea">,Uncapitalize<"Tea">];const n:Names=["TEA","tea","Tea","tea"]; console.log(n.join(" "));Which diagnostic and explanation match the rejected example under the lesson settings?
type Names=[Uppercase<"tea">,Lowercase<"TEA">,Capitalize<"tea">,Uncapitalize<"Tea">];const n:Names=["Tea","tea","Tea","tea"];What is Capitalize<"tea time">?