Lesson 1 / 7

Welcome to TypeScript: JavaScript with Types

TypeScript, created by Microsoft and first released in 2012, is a superset of JavaScript — every valid JavaScript file is already valid TypeScript. What TypeScript adds on top is a type system: you can describe what shape a variable, function parameter, or return value should have, and a separate compiler checks that your whole codebase actually respects those shapes, catching a large class of bugs before the code ever runs.

TypeScript does not run directly in the browser or in Node.js — it compiles down to plain JavaScript first. The types exist purely to help you while writing code and to catch mistakes at compile time; by the time your code actually runs, the types have been stripped away entirely and it is ordinary JavaScript underneath.

Installing TypeScript

npm install -g typescriptntsc --version

This installs the TypeScript compiler, tsc, globally via npm (Node.js’s package manager — you will need Node.js installed first, covered in the JavaScript course on this site).

Your first TypeScript file

function greet(name: string): string {n    return `Hello, ${name}!`;n}nnconsole.log(greet("Tutoline"));

Save this as hello.ts and compile it with tsc hello.ts — this produces a plain hello.js file you can then run with node hello.js, exactly like any other JavaScript file.

Why add types to JavaScript at all

JavaScript happily lets you call greet(42) even though greet was clearly written to expect a name, and the bug only surfaces later, possibly in production, possibly as a confusing error several function calls away from the actual mistake. TypeScript catches this the moment you write it, directly in your editor, before the code ever runs.

What you will build across this course

By the end of this course you will understand TypeScript’s type system, interfaces, generics, and classes — enough to work confidently in the large share of modern JavaScript codebases (including most professional React and Node.js projects) that are written in TypeScript rather than plain JavaScript today.