4 ms·
TypeScript is the biggest factor that made JavaScript coding bearable to me. Before that, I was collapsing under the weight of my ~1000-line JavaScript programs
by nayuki 5y ago
TypeScript is the biggest factor that made JavaScript coding bearable to me. Before that, I was collapsing under the weight of my ~1000-line JavaScript programs, because I couldn't mentally keep track of types and names. Similarly, revisiting my old JavaScript programs after a year, it was tedious to reread my code to infer the types and structures.
I know the rules of JavaScript, including all the weird type coercion stuff, undefined, etc. I know how to write correct programs, but I hate the human effort of having to jump around my codebase to recheck definitions and to double- and triple-check my work for silly mistakes.
Writing TypeScript code makes me do a bit more work upfront to annotate types. But in exchange, the compiler helps me tremendously in tediously checking all the types and names. Functions with types are more self-documenting than untyped functions; it's easier to read and figure out what a function does at a glance.
In a sense, compile-time type-checking is more powerful than unit tests because unit tests only cover functions and branches and (run-time) types that are actively taken, whereas type checking applies to all code all the time.
Before discovering TypeScript, I used this workaround a few times: For complicated pure algorithm / data structure stuff (not DOM or user interface stuff), I would prototype the program in Java with all the glorious types, test the heck out of it, and then translate it line by line to JavaScript.