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.