You are viewing a free preview of this lesson.
Subscribe to unlock all 12 lessons in this course and every other course on LearningBro.
TypeScript provides a rich set of built-in types that map closely to JavaScript's runtime values. Understanding these foundational types is essential before moving on to more advanced features. This lesson covers every primitive type, arrays, tuples, and the special types that TypeScript adds on top of JavaScript.
A type annotation tells the compiler what type a variable, parameter, or return value should be. You write a colon followed by the type after the identifier:
let username: string = 'Alice';
let age: number = 30;
let isActive: boolean = true;
TypeScript can often infer the type from the assigned value, so explicit annotations are optional in many cases. However, they are invaluable for function signatures and complex objects.
Represents textual data. Template literals are fully supported:
let greeting: string = 'Hello';
let message: string = `Welcome, ${greeting}`;
All numbers in TypeScript (and JavaScript) are floating-point values. There is no separate integer type:
let count: number = 42;
let price: number = 9.99;
let hex: number = 0xff;
let binary: number = 0b1010;
Subscribe to continue reading
Get full access to this lesson and all 12 lessons in this course.