Primitive types
TypeScript's simplest building blocks.
In TypeScript, every value has a type. The three simplest are string for text, number for any number, and boolean for true or false.
TypeScript checks these for you. If you treat a number like text, it tells you — before the bug ships.
Think of a cricket player. Their name is text. Their jersey number is a number. Whether they're the captain is true or false. Three attributes — three types.
Here's the code.
The same three types you just tapped, written out as TypeScript. Each comment shows the inferred type.
const batter = { name: 'Aarav Sharma', // string jersey: 7, // number isCaptain: true, // boolean };
Three types, three attributes.
You just used three TypeScript primitive types: a name is a string, a jersey number is a number, and the captain flag is a boolean.
Every value in your TypeScript code is one of a small set of types. Today you met the three simplest. The rest of the lessons build on these.