TypeScript is an open-source programming language that adds static typing to JavaScript. A TypeScript file usually has a .ts extension, is checked by the TypeScript compiler, and is then compiled to plain JavaScript.
The most important idea is that TypeScript does not replace JavaScript. It builds on JavaScript. Valid JavaScript is often valid TypeScript, and every TypeScript project eventually produces JavaScript that browsers, Node.js, or build tools can run.
JavaScript is flexible, but that flexibility can hide bugs in large applications. A property may be missing, a function may receive the wrong value, or an API response may be used incorrectly. TypeScript helps by checking these contracts before runtime.
In small scripts, dynamic typing may feel fast and simple. In larger projects, explicit types help teams understand what values are allowed and what a function promises to return.
TypeScript is common in modern front-end and full-stack development. Angular uses TypeScript by default, React and Vue teams often choose it for safer components, and Node.js backends use it to make services easier to maintain.
It is also popular in frameworks such as Next.js, NestJS, Remix, Express projects, serverless functions, browser libraries, design systems, monorepos, and shared API packages. The main benefit is consistency: the same type definitions can guide both client and server code.
TypeScript should be understood as a development-time layer on top of JavaScript. It does not change how the JavaScript runtime behaves unless your code or build process adds runtime checks.
This distinction matters. TypeScript can warn that a value should be a number, but if data comes from a user, URL, database, or API response, your application may still need runtime validation.
| Feature | JavaScript | TypeScript |
|---|---|---|
| Typing | Dynamic | Static during development |
| Runs directly in browser | Yes | No, usually compiled first |
| Compile-time checks | Limited | Strong type checking |
| Learning curve | Lower | Adds type concepts |
| Best fit | Scripts and flexible runtime code | Medium to large applications |
A type annotation tells TypeScript what kind of value is expected. If you assign a different kind of value later, TypeScript reports an error.
The code below still compiles to JavaScript, but the TypeScript compiler understands the intended shapes while you are writing the program.
let courseName: string = "TypeScript";
let lessonCount: number = 15;
let isPublished: boolean = true;
// courseName = 42; // Error: number is not assignable to string
console.log(courseName, lessonCount, isPublished);
The best way to learn TypeScript is not to annotate every single expression. Start with function parameters, return values, object shapes, and API data. Let TypeScript infer simple local variables when the value is obvious.
As you move through this tutorial, focus on useful contracts. A good type should make code easier to understand, safer to refactor, and harder to misuse. If a type becomes difficult to read, simplify the model or split it into smaller pieces.
Explore 500+ free tutorials across 20+ languages and frameworks.