FRGet In Touch
← Tech stack

TypeScript

JavaScript with types: a language that catches mistakes while you type, before the code ever runs.

Type
Programming language (typed superset of JavaScript)
Created by
Microsoft, open source (Apache 2.0)
Compiles to
Plain JavaScript
In my stack
React, React Native, Next.js and Node.js code

What it is

TypeScript adds types to JavaScript: you say that a function takes an inspection and returns a string, that a status can only be “open” or “closed”, that a field may be missing. The editor and the compiler then check every line against those rules and point out mistakes before the app runs.

Any JavaScript is valid TypeScript, so a project can adopt it file by file. The types disappear when the code is compiled, and what runs in the browser, on the phone or on the server is plain JavaScript. It is now the default for most React, React Native, Next.js and Node.js projects.

Why I use it

Whole categories of bugs disappear. Typos in field names, a forgotten case, a string passed where a number is expected: the compiler catches them, not the user.

Safe refactoring. Rename a field or change an API response, and every place that needs updating is flagged at once.

The code documents itself. Types show what a function expects and returns, and the editor autocompletes it, which makes a codebase faster to learn.

One contract for web and mobile. The same types describe the API for the dashboard and the mobile app, so both stay in sync with the backend.

Where I use it

The React dashboard and the React Native mobile app of the HR management system share TypeScript types for the API, and often the same validation rules. When the shape of a leave request changes, the compiler shows every screen on web and mobile that needs to follow. I use it the same way in Next.js and Node.js projects.

Best use cases

  • Any web or mobile app that will be maintained for more than a few weeks.
  • Projects with several developers, where types act as a contract between parts of the code.
  • Apps with a web and a mobile side that share models and validation.
  • Node.js backends and tools, where a wrong field name would otherwise only show up in production.

When I’d use something else

For a tiny script or a quick experiment, plain JavaScript is faster to write and types add little. Types also only exist at compile time: data arriving from an API or a form still has to be validated at runtime, with a library like Zod. And for a backend where performance and simple deployment matter most, I use Go.

A small example

A status that can only be one of three values, each with its own fields. TypeScript knows which fields exist in each case, and rejects an inspection that doesn’t match.

type Inspection =
  | { status: "draft"; id: string; site: string }
  | { status: "submitted"; id: string; site: string; submittedAt: string }
  | { status: "closed"; id: string; site: string; closedBy: string };

function label(inspection: Inspection): string {
  switch (inspection.status) {
    case "draft":
      return "Draft";
    case "submitted":
      return `Submitted on ${inspection.submittedAt}`; // known to exist here
    case "closed":
      return `Closed by ${inspection.closedBy}`;
  }
}

label({ status: "closed", id: "42", site: "North yard" });
// Error: property 'closedBy' is missing

Often used with

Need a web or mobile codebase that stays reliable as it grows?

Get in touch and tell me about your project.