TypeScript A Rising Star? ⌨️

Ever heard of TypeScript? Microsoft released it 8 years ago and it has grown in popularity non-stop. Developer analyst firm RedMonk latest ranking put TypeScript as the 12th most popular programming language in the world, up from 17th just a year before. They looked at github repositories and Stack Overflow conversations to make the list.

npm developers did a survey of 33,000 developers from 156 countries who use npm: “Overall, 36 percent of npm users are writing TypeScript some or most of the time.”

Have I peaked your interest in TypeScript yet? Did you already know about it? There are lots of resources online to learn about TypeScript like their official website: https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html
and lots of youtube videos! I’d love to hear what experiences you guys have had with TypeScript, if you are planning on learning it or any warnings for beginners!

2 Likes

I’ve heard of TypeScript, and know that it’s related to JavaScript but introduces extra features and bits.

I only really started dabbling with vanilla JavaScript recently, so haven’t actually done anything with TS personally. I’m sure I’ll get to it eventually. :slight_smile:

1 Like

I’ve also barely looked at TypeScript. From my very brief look, and possibly sketchy memory, I seem to recall TypeScript allowing programmers to type variables & such, but typing is not required. Once I read that all valid JavaScript is valid TypeScript, I quit looking at it. Not sure I see the usefulness unless an organization were to strictly enforce it’s use. Not sure how that’s possible since valid JavaScript code won’t throw errors. Please correct me if I’m wrong, that’s just what I remember from a year or more ago.

2 Likes

I believe @joshgoldberg77279673 would be great to expand on why TypeScript is awesome and why it’s worth learning. Or maybe I’m wrong!

Hey sorry I just saw this notification! Yes, there are quite a few very good reasons to use TypeScript (and, like any tech, a drawback or two). The main Codecademy site’s codebase was converted to TypeScript in 2019, and we’re working on a TypeScript course for later this year.

It’s technically true that most valid JavaScript syntax is valid TypeScript syntax, but TS adds a lot of intelligence around finding runtime bugs in your code. For example, do you spot the bug here?

let myName = "irlfede";
myName.toUppercase();

It’s technically valid JS but TypeScript would tell you that toUpperCase()/toUppercase() is a typo.

TypeScript also lets you define the expected shapes of your variables, class members, function parameters, and so on - which is very useful as your code gets larger over time. If you’re, say, calling a function from an npm package that takes in a complex object as an argument, TypeScript will tell you in your editor what the allowed fields are named & supposed to be, and it’ll yell at you if you get it wrong.

Re enforcing, there are a few strategies you could apply. Projects run by experienced TS devs that start with TS often have very strict usage, but if you’re not particularly TS experienced and/or your project isn’t already converted, there are looser compiler settings that allow less strictly typed code while still giving you most of the benefits. The Webpack codebase, for example, is actually deliberately still written in JavaScript (and last I checked plans on staying that way), but uses TypeScript as an extra layer of safety.

If you’re just getting started with JavaScript, or your project isn’t bigger than a few files, TypeScript might not be a great match for you. It’s got a bit of a learning curve so jumping into it before you’re ready can be painful – and any tech can be hard to learn even when you are ready. But if you’re working on bigger stuff or just want to level up I’d definitely recommend learning it.

3 Likes

@irlfede typescript is a super set of JavaScript … and the syntax is really really super strict … you can’t miss a semicolon… :relieved: :confused: