DEV Community

Cover image for You should probably learn TypeScript
Ben Halpern
Ben Halpern

Posted on

You should probably learn TypeScript

Yes, you.

This post is trending right now...

It's certainly always valid to compare and contrast... Especially as a project decision maker. The pros and cons are very relevant, but as an individual developer, these tradeoffs should not affect your decisions on whether to explicitly take the time to learn this technology.

Learn TypeScript in order to be more employable because of the popularity of this approach to JavaScript, but also learn TypeScript because it is going to open you to new paradigms you might otherwise neglect.

As far as bang-for-your-buck goes, it's probably one of the more valuable learning opportunities out there right now. It's trendy and popular, but it is hardly "hipster technology". You are going to get a lot out of learning this programming language.

... But once you learn it, don't demand that your company immediately adopt it. There are a lot of valid reasons to stay the course. Rewrites are expensive.

Happy coding. ❤️

Top comments (27)

ben profile image
Ben Halpern

To re-iterate the point in comment form... The values and tradeoffs of TypeScript no longer really matter for you the individual developer. Organizations or leads tasked with making the tradeoff choices still have plenty to talk about, but the technology is just at the generically worth learning phase in its life. You will generally gain a lot from learning TypeScript even if you never write a line of production code. I wouldn't say that around anything more esoteric, or strictly due to popularity. Learning TypeScript is good inherently for your resumé and your developer soul.

simonireilly profile image

As a lead, with a multi-language mono-repo, we onboard, and get people productive with Typescript faster than other languages.

They can understand the scope and cost of changes, because typing shows how data objects flow through the system.

And when we share code with other value streams, interfaces are documented.

bennycode profile image
Benny Code

From what I have seen, those anti-TypeScript posts are created out of frustration about compiler errors. Especially at the beginning it is easy to get sad because the compiler knows better than you. I have been at this stage myself but many compiler errors later, I am happy to call TypeScript my friend.

My team and I are building Wire, an end-to-end encrypted messenger, with TS and it would have been a mess to maintain our very large codebase without it.

I can only recommend every beginner to keep practicing coding with TypeScript. And if you are running into problems, feel free to ask me. 🙂

I also created a guide for solving TypeScript errors.

fjones profile image
FJones • Edited

I dislike TypeScript because it is highly opinionated, has illegible syntax that puts Regex, Lisp, and Haskell to shame, and because that very frustration with compiler errors leaves my junior devs with a wave of any type declarations just to get it running. Operationally, I find it to be a waste of time in development and code review. It also provides a false sense of security - the belief that a type system solves all of your programming woes. Maybe I'm too used to weakly-typed languages, but I often very much appreciate the flexibility of it, and I find it a lot easier to infer types than to write TS type definitions all day.

As an individual developer, I can appreciate the benefits TypeScript can provide, when done right and when consistently enforced. Contrary to what many people list as their motivator, I think TS is much better suited for small, self-contained projects than for large, growing codebases with a lot of developers of varying skill levels. But as a tech lead, I would rather see improvements to innate programming skill through code review, than through an opinionated tool that frustrates the developer to the point they ask me for help - and ultimately don't really understand it.

Edit: Just to add, yes, obviously I do think at a certain stage everyone vaguely involved with JavaScript should take a dive into TypeScript, just as a means of getting familiar with it and being able to understand it conceptually as well as reading foreign code. But as noted in the OP and my personal conviction: Don't try to push it as the be-all-end-all that must now be used everywhere, even if you like it. Maintainability and team management requires a lot more than a fancy tech stack.

bennycode profile image
Benny Code

Why do you think that TypeScript is opinionated? The development of TypeScript happens in the open source space, so every developer can give his or her input to the design of the language. That actually makes it very transparent and less opinionated.

I don't think that TypeScript provides a false sense of security. Ofcourse, TypeScript cannot help you when you use the compiled code with plain JavaScript because then you are allowed to pass incorrect types to a function. But that's the problem of JavaScript, not TypeScript.

If your junior developers use the any type where it is not needed, it means that they don't have a good overview about your application. This is a good time for you to talk with them about how your application is going to be used and how it should behave.

TypeScript also offers type inference, so there is no need to "write TS type definitions all day". You can read more about it here:

I don't think that TypeScript should be a replacement for code reviews. You need both and TypeScript will actually make your reviews much easier because the compiler will flag already issues to your team mates before they flag them to you.

Again, TypeScript is not just a "fancy" stack. CoffeeScript was a fancy stack but TypeScript provides real value with a real compiler. One of the best things about TypeScript is that you can use it with plain JavaScript code, so you can easily start with it and integrate it slowly in your application. That's perfect for beginners or a migration of an existing code base. You can write the JS code, that you are familiar with, in a file with a ".ts" extension and if you feel experienced enough, you can start using advanced programming techniques und type guards where needed.

easonsoong profile image

I don't like TypeScript as first because I can not see the value of writing those TS type definitions. And writing and checking those weird TS types and grammer also takes time that should be used for testing my code. But I found it valuable one day when I have to refactor part of my code, it may return some obj that play a role everywhere in my project. After update my code, typescript found some code that has a wrong TS types match, and I can fix that in a few minutes with more confident that I have fixed all the problem. It is worth trying Typescript.

mykeels profile image
Backlog Slayer

Now you have to drop a link to Wire if it's public

bennycode profile image
Benny Code

My pleasure: 😊

rjzauner profile image

I used think that TypeScript was not really necessary to learn and only started to learn it, because the company I worked for used it.

A few lines of code later and I admitted to being totally wrong about Typescript.

It is like you said, you learn so much by writing and playing around with it.

And it truly does make things a lot easier once you have gotten the hang of it.

whobeu profile image
Robert G. Schaffrath

I basically dove into Typescript by taking existing JavaScript I had written and converted it to Typescript. Funny thing is that in the process I did find a few bugs in the JavaScript code that Typescript gleefully pointed out.

I turned 59 in June so it is still possible to learn new things. In fact I find Typescript/JavaScript to be more fun to work in than C# which had been my favorite.

eidellev profile image
Lev Eidelman Nagar

Agreed. You can also gain many of the benefits of typescript without rewriting your entire code base by gradually introducing TS.

nickytonline profile image
Nick Taylor

Enable allowJs and checkJs in the compiler options and already you'll see benefits. 😎

wolfhoundjesse profile image
Jesse M. Holmes

I especially love this about TypeScript. You can add it to a project without renaming your files, and turn on two or three strict features a week until the team has a handle on the basics.

thexdev profile image
M. Akbar Nugroho • Edited

The main reason I used TypeScript for my current projects is because TypeScript supports static typing.

No doubt, I have written JavaScript for 2+ years and the main problem I faced is "what data type of this variable/constant/etc".

Yeah, you can comment your code, but write a lot of comment for knowing a data type of a variable is not effective.

094459 profile image
Ricardo Sueiras

I think that I am at the stage that I just cannot ignore Typescript; I do a lot of work in CDK, and whilst it caters for many languages, it is developed in Typescript and most of the examples/demos are written in it to. What I now need to do is look for some interesting ways in which I can make that learning enjoyable ;-)

nasidulislam profile image
Nasidul Islam

I was a skeptic of TS before I tried it. I always wondered why it was necessary - why couldn't we achieve what it is trying to achieve with just better checks and balances in vanilla JS?

Now that I've dabbled in to it - even though I'm still a noob, I see its value. I work at a place that, I would say, has bigger than average turnover ration. By that I mean, devs are frequently walking in and out through the door. For a codebase that doesn't have too many seasoned devs, TS has been the oasis in a desert

joelbonetr profile image
JoelBonetR 🥇

You need to add context to this post.
I mean, if you are a senior Java or C# (to say something) why should you want to move to TS? If you want to became an AI dev better learn python. Also nothing to do for data career path.

When in learning phase it could be great if you are going for full JS stack, in which case knowing TS is an addition as you'll find it in some companies mixed with JS or using TS as main implementation but otherwise you may probably better focus on your stack.

Either way learning TS is not an excuse for not deeply learn JS and I would suggest to first learn JS in deep and then learn about TS.

From the TS Doc

Learning JavaScript and TypeScript

We frequently see the question “Should I learn JavaScript or TypeScript?“.

The answer is that you can’t learn TypeScript without learning JavaScript! TypeScript shares syntax and runtime behavior with JavaScript, so anything you learn about JavaScript is helping you learn TypeScript at the same time.

There are many, many resources available for programmers to learn JavaScript; you should not ignore these resources if you’re writing TypeScript. For example, there are about 20 times more StackOverflow questions tagged javascript than typescript, but all of the javascript questions also apply to TypeScript.

If you find yourself searching for something like “how to sort a list in TypeScript”, remember: TypeScript is JavaScript’s runtime with a compile-time type checker. The way you sort a list in TypeScript is the same way you do so in JavaScript. If you find a resource that uses TypeScript directly, that’s great too, but don’t limit yourself to thinking you need TypeScript-specific answers for everyday questions about how to accomplish runtime tasks.

jwp profile image
John Peters • Edited

TypeScript taught me to like Javascript after avoiding Javascript for 10 years. I was always a strong typer and into OOP. Now I'm just a polyglot.

omawhite profile image
Omar White

My team has been gradually writing new code in typescript. It's been a long process, but I think gradually adopting like this is the way to go. It's also made learning typescript easier for me.

heyrohit profile image
Rohit Gupta

Title should be : You should probably learn TypeScript

pencillr profile image
Richard Lenkovits

I just can't make myself. It's so cumbersome.

muncey profile image

Completely agree, Typescript is a great and important language to learn. It also makes it easier to bring back end developers into the front end world.

link2twenty profile image
Andrew Bone