ENES

TypeScript

JavaScript with types added, so many mistakes are caught before the code runs.

A TypeScript file with type labels goes through a checker that flags a mistake, then comes out as plain JavaScript

TypeScript is a programming language made by Microsoft and released in 2012. It is JavaScript plus one big addition: types. You can label a variable as a number, a function as taking a string, or an object as having a name and an email. Every valid JavaScript program is also valid TypeScript, so teams can adopt it gradually, one file at a time.

Browsers and Node.js run JavaScript, not TypeScript. So before running, the TypeScript compiler, tsc, checks the code and then strips out the types, producing plain JavaScript. The check is the point: if you pass text where a number was expected, call a function that does not exist, or forget that a value can be empty, TypeScript tells you while you type, not when a customer hits the bug.

In big projects that changes a lot. Editors use the types to autocomplete, jump to definitions and rename things safely across thousands of files. Types also work as documentation that cannot drift out of date. That is why TypeScript became the default for many web and Node.js teams. The checks only exist at build time, though: data that comes from outside at runtime, like a response from an API, still has to be validated.

Keep in mind

Go deeper

Related terms

More in Software