DEV Community

Discussion on: Seven lessons I wish I learned earlier about Typescript

Collapse
 
stereoplegic profile image
Mike Bybee • Edited

Something lost in all the euphoric tweets about how Typescript will save JavaScript is simply how hard it is for someone new to pick up.

Been saying that for years, often while using TS and trying to guide junior devs with it.

I have a gut feel that a lot of the folks proclaiming how Typescript made Javascript makes sense are coming from another typed language.

Said that over and over again too. And that's why I think it's detrimental to learning actual JS when imposed on junior devs too early.

Collapse
 
chrisdhanaraj profile image
Chris Dhanaraj

Yep, totally agreed! I view Typescript as just another skill to learn on top of JavaScript, as opposed to a straight replacement. You're never going to be guaranteed that you'll always be working in Typescript codebase, and the fundamentals are always critical.

Having said that, I'm also mindful that a lot of job postings these days (even for "junior" devs) are sticking Typescript in there, so I totally get the drive to learn it.

Collapse
 
aritik profile image
Ritik Ambadi

Like you said , how typescript is touted to be something that is supposed to make JavaScript finally make sense.
What if javascript makes sense to me as it is? I did hate the language earlier but I absolutely love using it now. Don’t see any reason why I should have to learn typescript.

Collapse
 
chrisdhanaraj profile image
Chris Dhanaraj • Edited

Hmmm, to answer "why should I learn Typescript," I think for me it boils down to two things

  1. Typescript is (not to discount actual docs) the easiest way to tell team members what a function / component / piece of code is supposed to take in and do. When using a helper function your teammate wrote and typed, it's suddenly so easy to figure out what to pass into it without having to jump somewhere else. Staying in that flow state makes writing applications much much easier when everything is properly typed.

  2. There's a class of bugs (I passed in the wrong parameter! I used a string instead of a number!) that simply doesn't happen in Typescript. The compiler will throw an error for you and you can correct it before it gets there.

The first is the most important to me but it's caveated that it works best when there's a full buy-in to Typescript. Partially typed code still makes you jump around to figure out what's going on, and you don't get the same feel. It's also much more important when you have a bigger team! If it's only you writing an application, then maybe the drive for this Is much less. Although, you may do something like me where I'll begin a side-project, abandon it for six months, and then have no idea what I was doing before. Typescript could come in handy there!

The second is important just for general ergonomics; the first time Typescript tells you, "oh hey! this function expects an array and you only passed a single item" is a nice lil rush.

With all that, Typescript still means you're investing time and energy to solve those two problems above - so IMO if you're not having them or they're not super important to you, then I don't think it's worth your time!

Thread Thread
 
stereoplegic profile image
Mike Bybee

This is one of the more objective defenses of TS I've seen, so thank you for that. With that said, I believe it's more important to teach junior devs proper commenting in JSDoc, and ESLint can catch those same errors if set up properly.

As I commented recently in another TS article, the typeof keyword is just one example of the confusion that awaits juniors still trying to learn JS proper when you impose TS on them. And while catching type errors is clearly important, I'd argue that they need to understand JavaScript's dynamic typing first and foremost.

Thread Thread
 
chrisdhanaraj profile image
Chris Dhanaraj • Edited

Yep, 100% agreed that pure juniors would get more out of learning JS proper first and move on after. There's only so much your brain can soak in at once, and I don't equate this to learning JavaScript first vs jQuery/React/Angular/library where the latter can sometimes give beginners a rush of "hey I built something" and help spark learning.

But hey - TypeScript code can definitely give you that feeling of "hey look how well organized my code is" and maybe that does it for someone. Especially if you're moving from a different typed language, maybe it makes more sense to you than raw JS and you can back you way in after.