DevPath · Learn to code ESPTEN

Introduction to TypeScript

Why types and basic types

What is TypeScript?

TypeScript is a superset of JavaScript that adds a static type system. All valid JavaScript is valid TypeScript, but TS lets you annotate the types to catch errors before running.

Note: the browser doesn't understand TS directly; a compiler translates it to JavaScript. Types only exist while you write and compile.

Why use types?

Basic types

let age: number = 30;
let name: string = "Ana";
let active: boolean = true;
let tags: string[] = ["js", "ts"];
let anything: any = "whatever"; // avoid it when you can

Often you don't need to annotate: TypeScript infers the type from the value.

let total = 42; // TS deduces that total is number
// total = "hi"; // ❌ Error: you can't assign string to number

In this course

The exercise editor runs plain JavaScript. In the lessons you'll see type syntax to learn the concept, but in the exercises you'll write the logic in regular JS.

Examples

The same logic works in JS (without types)

let age = 30;
let name = "Ana";
let active = true;
console.log(typeof age, typeof name, typeof active);
Put this into practice

DevPath is a hands-on course: you read the theory here; in the app you put it into practice with exercises that really run, offline.

Start free in the app →
Interfaces and function types →