## glossary

What is TypeScript?

TypeScript is a language created by Microsoft in 2012 that extends JavaScript by adding a static type system. It is a superset: every valid JavaScript file is already valid TypeScript, which allows gradual adoption.

One important detail: browsers do not execute TypeScript. The code goes through a compiler that checks the types and emits plain JavaScript — the types exist only at development time and disappear from the final file.

The problem it solves

The same bug, caught at different moments
// JavaScript: breaks in production, when a user clicks
function calcularTotal(itens) {
  return itens.reduce((soma, i) => soma + i.preco, 0);
}
calcularTotal(null); // TypeError at runtime

// TypeScript: the editor underlines it before you save
interface Item {
  nome: string;
  preco: number;
}

function calcularTotal(itens: Item[]): number {
  return itens.reduce((soma, i) => soma + i.preco, 0);
}
calcularTotal(null);
// error: Argument of type 'null' is not assignable to 'Item[]'

The difference is not cosmetic. The error leaves the user’s environment and returns to the developer’s, where it costs minutes instead of an incident.

What typing delivers beyond checking

  • Real autocomplete — the editor knows which fields exist on each object, no guessing.
  • Safe refactoring — renaming a field updates every usage and flags whatever became inconsistent.
  • Living documentation — the function signature describes the contract without relying on an outdated comment.
  • Confidence to touch legacy code — the compiler shows the blast radius before the deploy.

Features beyond the basics

The type system is expressive enough to model business rules. Union types restrict the possible values, generics create reusable components without losing type safety, and narrowing lets the compiler understand that, inside an if, a given value can no longer be null.

Modeling impossible states out of the code
type Requisicao =
  | { estado: 'carregando' }
  | { estado: 'erro'; mensagem: string }
  | { estado: 'ok'; dados: string[] };

function render(req: Requisicao) {
  if (req.estado === 'ok') {
    return req.dados.join(', '); // TS knows 'dados' exists here
  }
  // and knows 'dados' does NOT exist in the other branches
}

Is it worth adopting?

For small, throwaway projects, the setup cost may not pay off. For any code that will be maintained for months or by more than one person, the answer is almost always yes — and the payoff grows with team size. The detailed comparison is in the article JavaScript vs TypeScript.

## faq

Frequently asked questions

Does TypeScript make the application slower?

No. The types are stripped at compile time, so the generated JavaScript performs identically to what you would write by hand. The only cost is build time, during development.

Can I migrate a JavaScript project gradually?

Yes, and it is the recommended approach. You enable TypeScript with loose rules, rename files as you touch them, and progressively tighten the compiler options. There is no need to halt development to convert everything.

What does the any type mean and why avoid it?

any turns off type checking at that point, reverting to plain JavaScript behavior. Overusing it cancels out the benefit of adopting TypeScript. When the type is genuinely unknown, unknown is safer: it forces you to check before using the value.

## read next

Related articles