Technology · Language

TypeScript — types instead of documentation nobody writes

We reach for TypeScript as soon as front-end code grows past the point where anyone can hold all of it in their head. Types describe what a function expects and what comes back from an interface — permanently, without anyone maintaining a wiki. The benefit shows up not while writing the code but while changing it, a year later.

where front-end code grows

What is TypeScript?

TypeScript is not a different JavaScript to us. It is the same JavaScript with a stated promise about what travels through the functions.

What we use TypeScript for

Everywhere front-end code amounts to more than a few lines of interaction. In Astro projects we write components and data access with types. In Shopware 6 themes we type our own plugins and the handover between Twig and JavaScript. For custom interfaces — configurators, editorial tools, dashboards behind a login — TypeScript is a precondition for us, not a flourish. Small scripts inside a WordPress page often stay plain JavaScript.

TypeScript has its greatest effect at interfaces. When a REST or GraphQL API returns data, types describe the response, and the compiler speaks up when the back end renames a field or makes it optional. Those types can be generated from OpenAPI descriptions instead of typed out by hand. Errors of this kind otherwise surface in the browser — in the worst case at the customer's end, on a Friday afternoon.

How we work with it

We start strict, because retrofitting is more expensive. strict is switched on, any needs a reason, and we check the types shipped with third-party packages rather than believing them. The compiler runs in continuous integration, not only on the developer's machine — otherwise the first red error eventually gets ignored. For existing projects the route is reversed: migrate step by step, file by file, starting where changes happen most often.

We build with Vite and check with ESLint and the TypeScript compiler separately — bundlers transpile, they do not check. We keep types close to the data: one source for the shapes that back end and front end share, rather than two definitions that drift apart. And we do not write types that only impress the compiler. A generic monster nobody reads is not documentation, it is a second language inside the project.

Limits: what TypeScript does not do

TypeScript checks what the compiler can see, and it only sees your code. Everything that arrives at runtime from outside is a claim to begin with: API responses, form data, values from local storage, content from the CMS. Treat them as typed without checking and you have safety on paper. At those edges we validate at runtime, for instance with Zod. A type error nobody verifies is a runtime error on a delay.

Not every project needs TypeScript. For a few lines on a landing page, the effort for build, configuration and type definitions is out of all proportion; there we write modern JavaScript and leave it at that. TypeScript also does not replace tests. It checks shapes, not behaviour — whether a price calculation returns the right number is beyond the compiler. And where types only pass with casts, the data model is usually the thing that is wrong.

Frequently asked questions

Is TypeScript worth it in small projects too?

For a few lines of front-end code, TypeScript usually is not worth it. The line runs where code is touched by more than one person or outlives the project it was written for. Above that size, typing pays off, because renames, refactorings and interface changes become visible instead of failing quietly. For a single script on a landing page, modern JavaScript is enough.

Can an existing JavaScript project be converted to TypeScript?

Yes, a conversion runs step by step and without a rebuild. TypeScript can run alongside JavaScript: you switch on the compiler, allow mixed files at first, then convert module by module, starting where changes are most frequent. What matters is raising the strictness early instead of living with loose settings for years. Otherwise you end up with a project that is called TypeScript and stays JavaScript.

Does TypeScript prevent errors in live operation?

TypeScript prevents one class of errors — wrong assumptions about the shape of data — and it does so before launch rather than after. What it does not prevent are mistakes in the business logic, and data that looks different at runtime from what was agreed. That is why we also validate incoming data at runtime and write tests for behaviour. Types and tests answer different questions; trading one for the other means losing something.

TypeScript: existing system or new build?

We also take over systems that were built elsewhere — after a look at the code and the hosting.

What else we build with

Call Start a project