TypeScript: should I stay or should I go

The many benefits of adopting TypeScript and why you should be embracing it in case you haven’t already

Mayumi Nishimoto
6 min readMay 23, 2022

--

Should I stay or should I go now?
If I go there will be trouble
And if I stay it will be double (….)

(The Clash — 1980's)

Whether you are starting a new project or working on an existing code base there is always the option of writing or maintaining it in pure JavaScript. JavaScript is well known, widely adopted and has a large community, being rated as the most commonly used programming language by Stack Overflow for 9 years in a row since 2012. It is the de-facto language of the web. With that information in mind, you may wonder, if that is so why bother with TypeScript? However, before answering this question, let’s understand what TypeScript is.

What TypeScript is (and what it is not)

TypeScript is a type system that can be optionally added to JavaScript code in order to support developers in catching errors and bugs early, even before the code is compiled and executed. In a nutshell, it works as a static type checker for JavaScript programs. Therefore, it is only “active” during development, operating as a “tool that runs before your code runs (static)” and ensuring that the “types of the program are correct (type-checked)” — TS handbook.

Note that the entire type system falls away, once the application is deployed and the program is running inside the browser or in any other runtime environment, such as Node.JS. But how so? When running your application, your code has to first be transpiled to JavaScript before it is executed in the browser or in a runtime environment.

Diagram showing that the code written in TypeScript code is first transpiled to plain JavaScript before being run in the browser
Your TypeScript code is transpiled to JavaScript before your application is executed in the browser

The browser or in a runtime environment has no idea what TypeScript is! Besides that it is important to notice that differently from other languages that are strongly typed, such as C# and Java, TypeScript does not give you any performance optimisation. TypeScript is a:

(…) strict syntactical superset of JavaScript.

--

--

Mayumi Nishimoto

Software Engineer in tireless pursuit of improving my craft and in a journey to learn by sharing with the community.