TypeScript is a programming language from Microsoft that adds static types to JavaScript. We write .ts files with type annotations, and the TypeScript compiler checks them for type errors and turns them into plain JavaScript that runs in any browser or in Node.js. Errors such as calling a method on undefined or passing a string where a number is expected show up while we write the code instead of in production.
We use TypeScript for JavaScript projects that grow beyond a few files, such as a React front end or a Node.js REST API, where a renamed field or a wrong argument type would otherwise reach the users.
A first TypeScript program needs Node.js and one npm package. The following example installs TypeScript 7.0.2 in a new Node.js 22 project, and then compiles and runs a one-line file.
npm init -y
npm install --save-dev typescript@7.0.2
echo 'const user: string = "Lokesh"; console.log("Hello " + user);' > hello.ts
npx tsc hello.ts # creates hello.js
node hello.js # Hello Lokesh
Notice that tsc writes hello.js next to hello.ts, and node runs that JavaScript file, not the TypeScript source.
Node.js 22.18 and newer can also run a .ts file without compiling it, with node hello.ts, because it removes the type annotations before running the file. Node.js does not check the types, so we still run tsc to find type errors.
This page is the starting point for every TypeScript tutorial on this site. We grouped the articles by topic and ordered them so that a beginner can read them from top to bottom, and each article has a runnable project in the TypeScript-Examples repository on GitHub.
1. Getting Started
Start here if TypeScript is new to you. These articles explain what TypeScript adds to JavaScript and how the compiler and tsconfig.json work, and they cover variables and loops.
- Getting Started with TypeScript explains what TypeScript is and shows how to install it and run the first program.
- TypeScript vs. JavaScript: Side-by-Side Comparison shows what the type layer adds and what stays the same at runtime.
- Difference between Transpiler and Compiler – TypeScript explains why tsc is called a transpiler and what it outputs.
- TypeScript Compiler Configuration – tsconfig.json lists the compiler options that matter for a new project.
- Difference between let, var and const in JavaScript compares block scope and reassignment for each keyword and says which one to use.
- JavaScript Variable Hoisting shows what hoisting does to var, let, const and functions.
- TypeScript For-loop, For..of and For..in with Examples covers for, for…of, for…in and forEach().
2. Types and the Type System
The type system is the reason to use TypeScript. These articles go from the basic types to unions, literal types, enums and dates.
- TypeScript Types and Type System – HowToDoInJava introduces primitives, any, unknown, never, arrays, tuples and type aliases.
- TypeScript Union Types with Example shows how to combine types with | and how to narrow them.
- TypeScript Literal Types – HowToDoInJava uses exact values as types and explains as const.
- TypeScript Enum (with Examples) compares numeric, string and const enums with the as const alternative.
- JavaScript – Difference between undefined and null explains the two empty values and how to handle them with ?? and optional chaining.
- JavaScript – Truthy and Falsy Expressions lists which values count as true or false in a condition.
- TypeScript Date (with Examples) covers the Date object from creating to formatting dates, plus the Temporal API.
3. Operators
These articles cover each group of operators, with the cases where TypeScript reports an error that JavaScript would accept.
- TypeScript Arithmetic Operators covers +, –, *, /, %, ** and number pitfalls.
- TypeScript Comparison Operators shows how to compare numbers, strings, dates and objects.
- TypeScript Logical Operators covers &&, ||, !, ?? and logical assignment.
- Equals Operator ( == ) vs Strict Equals Operator ( === ) explains why === is the default choice over ==.
- TypeScript / JavaScript Spread Operator (with Examples) shows how to copy and merge arrays and objects with ….
- TypeScript Template Strings goes from template literals and tagged templates to template literal types.
4. Arrays
Arrays are the most common collection in TypeScript code. The overview covers typing arrays, and the other articles go deep on one operation each.
- TypeScript Array or List (with Examples) shows how to create and type arrays, tuples and readonly arrays.
- TypeScript – How to Add Items to Array shows how to add items at the end, at the start or at any position.
- TypeScript – How to Remove Items from Array shows how to remove items by index, by value or by condition.
- TypeScript Array slice() with Examples shows how to copy part of an array with slice().
- TypeScript filter() Example: Filter Array of Objects by Property shows how to keep only the items that match a condition.
- TypeScript – How to Find Element in Array covers find(), findIndex() and findLast().
- TypeScript Array map() vs flatMap(): What’s the Difference? compares how map() and flatMap() transform items.
- TypeScript Array of Objects covers typing, sorting and grouping arrays of objects.
- TypeScript Array of Vectors: Multi-dimensional Arrays covers two-dimensional arrays and vectors.
5. Collections: Map, Set and Record
These articles cover the key-value and unique-value collections and how to choose between them.
- TypeScript Map (with Examples) shows how to create, iterate and convert a Map.
- TypeScript Set (with Examples) covers storing unique values and the new Set methods.
- TypeScript Record (with Examples) shows how to type objects with Record<K, V>.
- TypeScript Record vs Map: What’s Difference? explains when to use a Record and when to use a Map.
6. Functions and Error Handling
These articles cover function parameters, overloads, generics, callbacks and exceptions.
- TypeScript Optional and Default Parameters (with Examples) covers optional parameters, default values and options objects.
- TypeScript Function Types – HowToDoInJava covers rest parameters and spreading arguments.
- TypeScript Function or Method Overloading shows how to declare several call signatures for one function.
- TypeScript Generic Function, Class and Interface (+Examples) covers generic functions, classes and interfaces.
- TypeScript Callback Function Example goes from callbacks to Promises and async/await.
- TypeScript Exception Handling (+ Custom Exceptions) covers try/catch with unknown, custom errors and finally.
7. Interfaces and Classes
Readers coming from Java will find the familiar concepts here, along with the places where TypeScript works differently.
- TypeScript Interface Example: How to Create and Implement? shows how to declare and implement interfaces.
- TypeScript Extend Interface, Merge and Intersection Types covers extending and merging interfaces, and intersection types.
- Creating Objects from Interface in TypeScript shows how to create objects that match an interface.
- TypeScript Interface vs. Class: What’s Difference? explains when to use an interface and when to use a class.
- TypeScript instanceof with Class, Array and Interface covers instanceof, type guards and the in operator.
- TypeScript Method Override (with Examples) shows how to override methods with the override keyword.
8. Conclusion
For a structured path, we read the Getting Started and Types groups first, then Arrays and Collections, and finally Functions and Interfaces and Classes. Every article starts with a quick-reference snippet, so the groups also work as a reference when we need one answer fast.
9. References
The official TypeScript documentation is the source for the language rules used in these tutorials.
Happy Learning !!