Getting to Know Typescript

Ben Dunn
3 min readNov 12, 2020

Early in my software engineering journey, Typescript seemed daunting and unnecessary to me. I used to parrot complaints about it and reference it as a headache before I really knew anything about it. These days I know better, and now I say that stuff about Java instead (similarly unfounded, stay tuned for the heel turn). Typescript slows things down, sure, and it’s definitely fussy, but TS is the tortoise of the JS landscape. Slow and steady wins the race, assuming the ‘race’ is having less headaches and less issues when it comes time to launch.

Typescript is not another language, but a superset of old reliable Javascript. If you know JS, you can pick up TS and run with it without much of a learning curve, because all valid JS is also valid TS. When you make and write a .ts file, it will actually be transpiled into Javascript because of course browsers don’t speak Typescript! Typescript is all about typing, as Typescript takes the typically Dynamically typed Javascript and makes it a Static Typed language! In Static Typed languages, variables have a type that never changes! A string is a string, a number is a number, a boolean is boolean and so on. In JS we had the convenient but dangerous type coercion ability; TS does away with this, forcing you to explicitly state a variables type on declaration. Gone are the days of plugging in a string, treating it as an integer and getting an integer back! But why would you want this kind of limitation?

In short, Typescripts greatest strength is in it’s error handling. You’re going to get errors, LOTS of errors, working in TS. That’s because right in your IDE, Typescript will tell you exactly the problem it has with what you’re writing. This means that before you even try to compile the code, you know exactly where the problem is! This is a huge benefit, maybe not in your little student project but in larger scale enterprise projects for sure! Imagine getting a weird bug in your app and combing through line after line of cold indifferent JS code to find it. In TS, you know immediately when something may be a problem. You know because Typescript tells you, loud and clear.

Typescript makes you keenly aware of JS’s various types, which is a subtle benefit to TS that may not be immediately apparent. You get intimately familiar with these types, and TS forces you to be more thoughtful about how you use them, which in my opinion makes you a stronger programmer. There are numbers, strings, symbols, booleans, null, undefined and objects! Objects also encompass arrays, promises and functions, which again, encourages you to understand your good friend JS a little better. You can also set up Interfaces, which allow you to dictate the shape of the data you’re handling. Say you want to make damn sure that everything coming over from you backend is exactly the type you expect it to be. Create an Interface and you’re all set! In an object, for example, you can dictate that the key “name” is always a string, and “age” is always a number and so on.

Hopefully I’ve convinced you that Typescript is your friend! If it helps, it’s also an incredibly popular staple of job descriptions these days! So get out and start typing!

--

--