Primitive Wrappers: Number, String, Boolean
What you'll learn: Why you should avoid using Number, String, and Boolean as types in TypeScript.
The Core Concept
In JavaScript, there are primitive values like 42, "hello", and true, but there are also object wrappers for these primitives: Number, String, and Boolean (capitalized). These wrapper objects exist for historical JavaScript reasons, but in TypeScript, using them as types is almost always a mistake.
When you write number (lowercase) as a type, you're referring to the primitive value. When you write Number (uppercase), you're referring to the wrapper object — and these are not interchangeable.
Why This Matters
// ✅ CORRECT: Use lowercase primitives
let age: number = 25;
let name: string = "Alice";
let isActive: boolean = true;
// ❌ WRONG: Don't use uppercase wrappers
let count: Number = 10; // This works, but shouldn't be used
let title: String = "TypeScript"; // Avoid this!
let flag: Boolean = false; // Don't do this!
The uppercase versions create objects, which behave differently than primitives. For example, new Number(5) !== new Number(5) (two different objects), but 5 === 5 (same primitive value).
The Rule
Always use lowercase type names: number, string, boolean, symbol, and bigint. Never use the capitalized object wrapper types unless you explicitly need an object wrapper (which is extremely rare in modern code).
Think of it like this: the lowercase versions are the real data types; the uppercase versions are old containers you almost never need.
Key Takeaway: Always use number, string, and boolean (lowercase) as types in TypeScript — never their capitalized object wrapper equivalents.