Lesson 4 +10 XP

Primitive Types in TypeScript

TypeScript supports JavaScript's primitive types: number, string, boolean, symbol, and bigint.

Overview of Primitives

TypeExamplesDescription
number42, 3.14, 0xFFFloating point numbers and integers.
string

`sum: ${x}`

Array & Tuple Primitives

Arrays can be typed using array syntax type[] or Array<type>.


typescript
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.