Static type checking with TypeScript #1186
Replies: 1 comment 1 reply
-
To get it out of the way first: among the type-checking JavaScript compilers, TypeScript would also be my choice. It's more popular and proven than the alternatives. This is not to say that static typing itself is an easy choice. In my experience with TypeScript, it's three significant advantages are:
Which is to say, if you don't auto-complete, as a developer there is only one advantage. Granted, it's a big one! But that's it: it theoretically saves an X amount of your time. TypeScript still compiles to Javascript, so you don't see the performance advantage you might in languages that compile to machine code. And no statically-typed language will save you from writing bad code. As a project architect, one's likely to be big on 2. Nothing like a compiler to get folks to conform, because you can't eslint-comment-directive your way out of it. :P Now, Typescript's two disadvantages are:
The big question for developers is how Advantage 1 compares to Disadvantage 1. In other words, how does the time you save on debugging compare to the additional time you'll spend writing the code to begin with? Defenders of TypeScript will say of course you save time. I don't think the distinction is self-evident, and will vary from team to team and from project to project. It is certainly worth discussing, though. Auto-complete saves some additional time, doesn't it? It certainly can, and folks that like it are usually firmly in Typescript camp, because it makes it actually useful when writing JS code. And in practice, when it comes to developers, this is what the discussion is about. At this point in the discussion I usually snark at Java: it's such a bureaucratic, verbose language that it is basically impossible to be productive with without auto-complete. Where in the spectrum does Typescript stand? The learning curve should also not be dismissed. It is harder to learn and write TypeScript than regular JS, and should be discussed appropriately. What are the costs associated with having the current development team learn it? Are TypeScript developers more expensive to hire? And finally, thoughts on code standardization, quality, and dependability: all of these can be achieved with good engineering practices. I.e., good reviews and ample test coverage, all which you have to do anyway if you want dependable software. As mentioned above, static typing won't save you from buggy code. The question here is if static typing makes it cheaper. |
Beta Was this translation helpful? Give feedback.
-
The frontend code in Open edX repositories, including Paragon, have traditionally not used TypeScript, in favor of vanilla JavaScript. I think this may be because historically, edX has not had much internal domain expertise around TypeScript. Despite this, TypeScript has grown to be quite popular and commonplace for JavaScript developers, providing many great advantages at the short term cost of a small learning curve.
The main advantages we'd hope to get with TypeScript in Paragon are:
interface
)function renderItems(item) { ... }
?)Some foreseeable disadvantages:
More discussion of the advantages/disadvantages of moving to TypeScript:
Evidence of static type checking popularity
TypeScript is the 4th most popular file type on Github pull requests, whereas JavaScript is the 2nd. TypeScript's ranking has trended up over the past year.
source
TypeScript is the 2nd most "wanted" language developers hope to use, but aren't currently. Additionally, TypeScript is the 3rd "most loved" language.
source
From the 2021 State of JavaScript report, "Static Typing" ranked as the highest feature missing from native JavaScript.
source
From the 2020 State of JavaScript report, TypeScript received a 93% "would use it again" rating from JavaScript developers.
source
From the 2019 State of JavaScript report, ~60% of JavaScript developers have USED TypeScript and WOULD use it again, while ~22% WANT to try it (source).
Proposal
We'd love to collect feedback, thoughts, and concerns about moving Paragon to TypeScript. If you have strong feelings about static type checking via TypeScript for Paragon (other more broadly across Open edX), we'd appreciate your thoughts!
Beta Was this translation helpful? Give feedback.
All reactions