TypeScript, Transmissions, & Testing
One of the loudest arguments against using TypeScript is that it adds unnecessary cognitive load and uglies up the code. I agree that it does take additional effort to think through what your data model is when authoring code, but that when reading the code, it increases the speed of understanding how data is flowing through the application. It decreases cognitive load overall.
Why structural types matter
To understand why defining structural types is an effective way to convey meaning, let me make up a new word: hexplanar trinket. First, let me use it in context; this is similar to seeing variables in use in code:
The hexplanar trinket sat on the table waiting for its colored panes to be aligned.
Now let’s describe its properties instead:
A puzzle cube with 9 colored panes on each side
Trying to guess what something is by how it is used is always going to take longer than by reading a well written description. With static typings like TypeScript has, a developer can both use a definition of what something is and also look at the context in which it is used.
I personally spend at least eight times more time reading code than actually authoring it. I work on the east coast of the US so much of my work is financial, legal, or industry-specific. More than half of the applications I work on are no longer greenfield. Code reading speed is more important than code writing speed. So for me, it is a no brainer; Understanding code quickly is more important, so I should pick a statically typed language.
Tooling and why beginners benefit
In addition to making it easier to reason about code, let me talk about the auto-completion. Oh, how I love the auto-completion. With TypeScript, I don’t really have to look at documentation all that much. Since I use Visual Studio Code to do smaller projects like digital marketing, I get the benefits of vscode knowing about the APIs even if I don’t need a build system.
Testing, you still need it
Using a statically typed language helps developers make better assumptions about their functions and models. It is NOT A REPLACEMENT for testing. I have seen this used as an argument against TypeScript, but it is a logical fallacy. I haven’t seen any real claims that TypeScript is a replacement for testing. So test, damn it!
Automatic vs Manual Transmissions
As a mechanic’s son, I leave you with this. If you can have the car do something for you, why not have it do it? TypeScript can do so much for your project even if you never add a single type annotation, so why not use it?