# TypeScript

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

- Level: Intermediate
- Topics: Software
- URL: https://tidbit.legios.com.ar/typescript/
- In Spanish: [TypeScript](https://tidbit.legios.com.ar/es/typescript/)

**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.

## An analogy

A spell checker for the logic of your program. It does not change what you meant to write, and the reader never sees it, but it underlines the mistakes before anything is printed.

## Keep in mind

- TypeScript is JavaScript plus optional static types.
- It compiles to plain JavaScript; the types disappear at runtime.
- Catches many bugs in the editor and powers autocomplete and safe refactoring.
- Data arriving at runtime still needs validation.

## Go deeper

- [TypeScript (official site)](https://www.typescriptlang.org/)
- [TypeScript documentation](https://www.typescriptlang.org/docs/)

## Related terms

- [Programming language](https://tidbit.legios.com.ar/programming-language/): A precise, written language people use to give instructions to a computer.
- [Microsoft](https://tidbit.legios.com.ar/microsoft/): The company of Windows and Office, now just as much a cloud company with Azure.
- [JavaScript](https://tidbit.legios.com.ar/javascript/): The programming language that runs inside web pages and makes them interactive.
- [Web browser](https://tidbit.legios.com.ar/web-browser/): The app that fetches web pages from the internet and draws them on your screen.
- [Node.js](https://tidbit.legios.com.ar/nodejs/): A way to run JavaScript on servers and computers, outside the browser.
- [Compiler](https://tidbit.legios.com.ar/compiler/): A program that translates source code into instructions a computer can run directly.
- [Bug](https://tidbit.legios.com.ar/bug/): A mistake in software that makes it behave differently from what was intended.
- [API](https://tidbit.legios.com.ar/api/): The menu of things one program lets another program ask for.
