DEV Community

Tracy-Gregory Gilmore
Tracy-Gregory Gilmore

Posted on

My thoughts on the TypeScript debate

In recent weeks I have seen several posts asking questions such as:

Should I learn JavaScript or TypeScript?

Should we be using TypeScript on our project?

For me the answers are obvious but might not meet with wide approval.

My Opinion

Personally, I have mixed feelings about TypeScript but I do not think it is a bad thing. However, between JS and TS my preferred language remains JavaScript.

I have been writing TypeScript professionally day-in-day-out for the past four years but this is on top of 20 year's experience of writing JavaScript, with varying levels of competence.

To answer the first question "learn JS or TS" the answer has to be JS then TS. Nowadays to become a professional web application developer you need both. You first need a firm foundation in JS before adopting TS. After all, the web browser and Node do not understand TS (unlike Deno). When debugging code, you might have access to source maps that link the obfuscated JS code to the TS instructions but sometimes to need to delve deep into the JS and get as close to the JS processor as possible to discover the root cause of issues.

I am of the opinion that when developing a project in a team TS makes considerable sense especially when the team is indoctrinated in OOP. One of the worst arguments I came across of adopting TS was "Most of the team are actually C# developers and they do not want to learn JS". My answer would be "keep them backend but not on Node". The justification was that TS, with its strong data typing, is closer to C#, but this is a fallacy. TS provides some additional checking to help the developer identify potentially in appropriate use of variables (given a hint of their expected type) but this is a development-time, not a run-time feature.
I have had to battle this assumption several times and even Microsoft have changed their take on the role of TS in relation to JS.

TypeScript used to be described as being a superset of JavaScript as it added features to the language - but it does not. TS is little more than a perpetual linter statically checking your code, especially when used in conjunction with an IDE such as Visual Studio Code.
Now MS say "TypeScript is JavaScript with syntax for types", the actual checking being done by running the TSC command, by the IDE or by plugins to the IDE. But don't get me wrong, anything to help the developer identify bugs before the go to test/production has to be a good thing.

One issue I have found it TS pushes the development more along the OOP route than I like. As I extend my coding style to employ more FP (Functional Programming) techniques, I have found that TS can make the function declaration considerably more complicated but perhaps I am doing it wrong.

In summary

If you plan to work as a frontend developer on a team with more than one FE dev then you should learn TypeScript but this should be built on a good understanding of JavaScript to get the maximum benefit.

Discussion (1)

Collapse
brense profile image
Rense Bakker

I don't get why people keep using the last argument that somehow you would not be proficient at Javascript when you have learned Typescript... It's like the word "superset" has a different meaning to them?

After all, the web browser and Node do not understand TS

True the browser does not understand TS. However, Node is another story, as you said there's Deno, but there is also ts-node-dev (or ts-node), which understand TS.

One issue I have found it TS pushes the development more along the OOP route than I like.

Whether you use OOP or FP is up to the team. There's no difference between Javascript or Typescript, both can do either OOP or FP or any kind of mix of OOP and FP, which makes sense because Typescript is a superset of Javascript, so they support the same syntax for writing OOP or FP code. Personally I havent written a class in Typescript since React 16.8

It's understandable that C# developers would prefer TS over JS because they're used to a type safe language. The joke is on them though, because if they learn TS, they also know JS 😂