Embracing the red squiggles
Typescript is like a self-defined spell-checker, grammar suggester, and writing editor that proofreads your code while you program. But it’s only ever as good as you configure and maintain it. And if misused, those red squiggles that notify you of errors might hurt (ie. annoy) more than help.
Simply put, in Typescript, a data’s type is its shape or structure — that is, what properties and methods it is required to contain or optionally consist of.
The benefits of Typescript
Typescript’s rigid structure actually makes development far more enjoyable and reliable. Some of my favorite resulting features of Typescript include:
- When accessing data (like an object, array, or primitive), your code editor will remind you of what object properties and methods are available.
- If you try to access a non-existent object property, your code editor will let you know immediately.
- When defining typed objects, your code editor will remind you of what properties are required.
4) When using typed functions, your code editor will remind you of the necessary (or optional) function inputs and outputs.
This mostly means you won’t have to waste time confirming if an object you’re accessing has the properties you expect, or search for a function’s definition to see what arguments it takes. Just type your objects and functions, begin coding, and the options will immediately display themselves. Accidentally try to access a non-existent property, and a red squiggle will let you know immediately, rather than your console yelling at your at build time.
With this cognitive load lifted, you’ll have more time to focus on more pressing issues like systems design or UX.
Typescript is an incredibily powerful and robust tool for programmers who develop for the modern web.