Loading lessons...
Primitive Types in TypeScript
Primitive Types
TypeScript supports JavaScript's primitive types: number, string, boolean, symbol, and bigint.
Overview of Primitives
| Type | Examples | Description |
|---|---|---|
number | 42, 3.14, 0xFF | Floating point numbers and integers. |
string | "hello", 'world', `` sum: ${x} `` | Textual data and template literals. |
boolean | true, false | Logical truth values. |
bigint | 100n, BigInt(9007199254740991) | Arbitrarily large integers. |
symbol | Symbol("id") | Unique and immutable primitive values. |
Array & Tuple Primitives
Arrays can be typed using array syntax type[] or Array<type>.
let scores: number[] = [90, 85, 95];
let names: Array<string> = ["Alice", "Bob"];
// Tuple: fixed-length array with specified types at each position
let tuple: [string, number] = ["Alice", 25];
TL;DR
- Always use lowercase primitive type names (
number,string,boolean), not upper-cased wrappers (Number,String). - Tuples define fixed-length arrays with distinct element types at each index.