Advertisement
Beginner TypeScript, Primitive Types, Arrays & Tuples

What are TypeScript's basic primitive types, and how do you annotate a variable with one?

Short answer

TypeScript's core primitives are string, number, boolean, null, undefined, symbol, and bigint — annotate a variable using a colon followed by the type name after its identifier.

Save TypeScript mock interview
Advertisement
AModel answer
TypeScript's core primitives are string, number, boolean, null, undefined, symbol, and bigint — annotate a variable using a colon followed by the type name after its identifier.
let name: string = 'Sam';
let age: number = 30;
let isActive: boolean = true;
Real-world example
Explicitly annotating a function parameter's expected primitive type to catch incorrect calls at compile time.
Likely follow-ups
  • Why does TypeScript recommend lowercase 'string'/'number'/'boolean' instead of the capitalized 'String'/'Number'/'Boolean' wrapper object types?
Related topics