The natural progression therefore, is at some point, many developers will be faced with a question:
“How hard would it be for me, as an experienced programmer, to transition from JS to TS?”
The answer: very easy!
If you can conceive a venn diagram consisting of the following three categories:
- Understanding typed languages
Those are the three variables that form Typescript, especially when defined as the transition from JS.
With new languages we always have to learn new syntax, so that variable can almost never be omitted. The good thing about TS is that it sits directly on top of JS. It doesn’t change anything, but instead it just adds things.
As an experienced developer not only should syntax not be too intimidating of a painpoint, but also not that big of an issue. So let’s have a look at the other two!
The language choice(s) of formal education
Many schools where developers may have studied their craft offer exposure to a few, or even a range of, programming languages.
Most often these will be typed languages such as C, C++, C# or Java.
This bit of information is actually hugely important, because it means that most developers who took the classical route of formal education and then worked for some years, already have a tremendous amount of exposure to – and experience with – typed languages.
That’s an advantage because TS itself is a typed language, effectively just adding types to JS, at its core.
That makes the transition from JS to TS incredibly straightforward, because it removes one of the three variables we’ll have to deal with, namely understanding typed languages.
That means there’s another entire variable that we don’t have to mentally exhaust ourselves over!
So that leaves just one..
In order to fully utilize TS when transitioning from JS, the general advise is:
Just get started.
That was the same advise I was offered when I started converting a mid-sized codebase from JS to TS in late 2020, and so I did. I just started gradually implementing types, slapping on
any as necessary just to get the code running.
As I learned more TS and became more experienced in the landscape, I would change
anys, create custom types, infer interfaces from classes and much more.
… And this is the exact same advise I will give to you! Just get started 😄
It seems almost silly, but as TS is ‘just’ a type layer on top of JS you can get away with as much or as little as you please. As the adage goes:
“The best time to learn TS was yesterday, the second best time is now. “
There’s a bit of tooling involved with learning TS that can make it seem complex. We have
TS differs a bit in the sense that all tooling is opt-in. We are slowly seeing some tools win popularity and become more standardized, but for the most part you have complete freedom to choose from all available options.
That can be incredibly daunting if you come from a language where everything is pre-selected for you and things are done in one way, and one way only.
My point here is; learning and adapting the tooling can take a bit of fiddling and end up consuming time to get a setup that really fits you.
This is especially true if you’re working on an existing project that you gradually start converting.
You may or may not have heard of NestJS. NestJS is a framework that makes it straightforward to create really robust, enterprise-grade JS applications, written using TS.
I don’t yet have much experience with NestJS as I have only dabbled in it and created a few internal APIs using it. So far it is incredibly fast to work with and the type safety is just 10/10.
It really takes the TS experience to another level.
If you’re starting from scratch and/or you really don’t want to mess around with tooling for too long, I would highly recommend you check it out.
But that’s it!
In the post we covered how to transition from JS to TS as an experienced developer. I hope I made a few things clear and it is apparent that the tooling is where you will be spending a bit of time.
In the newsletter below I’ll do my best to share my progress as I venture more into NestJS, as well as giving you TS tips and tricks along the way to help you become a better developer 👏
Thank you for reading!