Want a faster signal before interviews? Take the Interview Ready Check →

DAY 1 OF 30

Primitive types

Yesterday, in one sentence

What does the TypeScript compiler do at build time?

Interview question

Is TypeScript dynamically typed or statically typed, and why?

A primitive type is one of the seven basic types built into TypeScript: string, number, boolean, null, undefined, symbol, bigint. You attach one to a variable with a colon after its name. This is called a type annotation.

The TypeScript compiler checks these annotations. If you assign a value that does not match the annotated type and you get an error.

let title: string = "Day 1";
let done: boolean = false;
let count: number = 30;

count = 31; // ok
count = "thirty"; // ❌ Type 'string' is not assignable to type 'number'

At build timeBuild Time the compiler turns all TypeScript into JavaScript by stripping out every type annotation, so the JavaScript that ships has no types in it at all.

Check yourself

Which of these is not a primitive type?
What are the 7 primitive types in TypeScript?