01What it is
Every web browser runs one programming language: JavaScript. Anything that moves, reacts or loads on a web page is JavaScript in the end. Since around 2009 it also runs on servers, through a program called Node.js, so a whole application can be written in it.
TypeScript is JavaScript with types added. A type says what kind of value something is. An invoice amount is a number. A customer has a name, which is text, and an optional VAT ID. A ticket has a status, which is one of four fixed words. In plain JavaScript these rules exist only in the developer's head. In TypeScript they are written into the code, and a program checks them.
Microsoft released TypeScript as open source in 2012. Its lead designer, Anders Hejlsberg, had earlier designed C#. Today TypeScript is one of the most widely used programming languages, and most large web projects start with it.
02How it works
Browsers cannot read TypeScript directly. Before the code is shipped, the TypeScript compiler reads it, checks every type and then writes out plain JavaScript with the types removed. The browser only ever receives that JavaScript. The types cost nothing at runtime: they do their work before the application starts.
The check covers the whole project at once. When a developer changes the shape of a customer record in one file, the compiler finds every other file that still uses the old shape and reports each of them with the exact line. Code editors run the same check while the developer types, so mistakes are underlined in red within seconds.
Types also serve as documentation. A developer who opens a function can see what it expects and what it returns without reading its body. Editors use the same information to suggest field names and to rename things safely across hundreds of files.
03An example from a business application
Take an application that issues invoices. The invoice has a net amount, a VAT rate and a gross amount. Somewhere a developer decides that amounts should be stored in cents as whole numbers, to avoid rounding errors, and changes the invoice type accordingly.
Without types, every screen, export and email template that still treats the amount as euros would keep running and show figures a hundred times too large. Someone would notice on the first real invoice. With TypeScript, the compiler stops the build and lists each place that has to change. The mistake never reaches a customer.
The same applies to many small things that go wrong in software:
- a field that is renamed in one place and forgotten in another
- a value that can be empty, such as a missing phone number, and is used as if it were always there
- a status that is misspelt, so a filter silently finds nothing
- a function that is called with its arguments in the wrong order
04Alternatives
In the browser, the only real alternative is plain JavaScript. It runs the same way and is quicker to start with, because nothing has to be declared. For a short script that is fine. For an application that several people change over years, the missing checks show up as bugs that are hard to trace.
On the server there are many other languages, among them Python, Java, C#, PHP and Go. Each is a sound choice, and many large systems run on them. Choosing one of them means the browser part and the server part are written in two languages. TypeScript allows one language for both halves, so a type such as an invoice is defined once and used by the screen, the server and the database code alike.
05What to look out for
TypeScript itself is free. What it costs is a little extra time while writing code, which is usually earned back the first time a change touches many files.
How much protection it gives depends on how it is set up. If you are buying software written in TypeScript, these points are worth asking about:
- Is strict mode switched on? Without it, many checks are off.
- How often does the code use the type any? It switches the check off for that value, and a lot of it means the types are decoration.
- Does the type check run automatically on every change, so code that fails it cannot be released?
- Are the types of data coming from outside, for example from another system's API, checked when it arrives?
06How we use it
We write both halves of every application in TypeScript, the screens and the server. With one language throughout, a data type is defined once, and the screens, the server and the database code all use the same definition. When the definition changes, the compiler shows us everything that has to follow.
Strict mode is on in all our projects. Data that arrives from outside, from a form or another system, is checked against its type before the application works with it.
Our AI agents write TypeScript as well. The type check is one of the automatic tests every proposed change has to pass on GitHub before it can be merged, so a change with a type error never reaches the running application.
Frequently asked questions
Do we need to know TypeScript to use the application?
No. TypeScript only matters to the people who write and maintain the code. Users see the finished application in their browser.
Does TypeScript make the application slower?
No. The types are removed before the code is shipped, and the browser runs plain JavaScript. The check happens once, during the build.
Can another developer take over TypeScript code later?
Yes. TypeScript is widely taught and used, so finding developers who know it is straightforward. The types also make unfamiliar code easier to read for whoever takes over.
Does TypeScript prevent all bugs?
No. It catches mistakes in how data is passed around and used. Whether a calculation follows the right business rule is checked by automated tests and by people reviewing the change.
Is TypeScript tied to Microsoft?
Microsoft develops it, but it is open source under the Apache 2.0 licence. The code it produces is plain JavaScript and runs anywhere, with no Microsoft product involved.