Do I really need to use TypeScript?

Sean Bradley
3 min readAug 10, 2022

No you don’t.

It’s an option for you, if you think you need it.

TypeScript is an extra layer to JavaScript to help ensure type safety.

“Type Safety? What?”

JavaScript is dynamically typed, which means that you won’t know if there are type related problems with your code until runtime.

TypeScript is checked for type safety as you write it. This is at least what happens when you use VSCode and you have TypeScript installed.

“I still don’t get it”

Well, lets try an example then.

In the 1st image, which is plain old JavaScript, the IDE isn’t aware that there is a problem with this code. You will find out when you run it.

npm install three

In the 2nd Image, which is still plain old JavaScript, but also after installing the Three.js TypeScript definitions, the problem still hasn’t been detected.

npm install @types/three

In the 3rd Image, I have renamed client.js to client.ts

As a result, the VSCode IDE thinks that it is a TypeScript file. Now it will be type checked as you write it.

The VSCode IDE has told me that there is a problem with this code before I even try to run it.

Also, the error message when I hover the mouse over the red squiggly, is also concise.

--

--

Sean Bradley

Developer of real time, low latency, high availability, asynchronous, multi threaded, remotely managed, fully automated and monitored solutions.