TypeScript

TypeScript

TypeScript is a superset of JavaScript that allows static typing. JavaScript is dynamically typed, which means that type checks happen during execution. TypeScript is statically typed, and checks are made while it compiles. TypeScript compiles down to regular JavaScript so it can be used on any project that uses JavaScript. Just one more way to catch bugs before production.

let yellow = "hi";
yellow = 35;

/// .ts TypeScript file
/// Type '35' is not assignable to type 'string'
let yellow = "hi";
yellow = 35;

/// .js JavaScript file
/// No error

I’ve used TypeScript before, but never really taken the time to sit down and learn the exact workings of it. With some time on my hands due to the Covid-19 debacle, I have finally sat down and started to get a better feel for it.

Why TypeScript?

I already have a decent enough handle on JavaScript to (sometimes) make it passed LeetCode tests, and my React skills are coming along nicely. TypeScript seemed like the next logical step to improve my code writing.

Implicit vs Explicit

With TypeScript you can use Implicit types such as `let yellow = “hi”` but you can also assign explicit types such as `let yack: number = 99` to explicitly assign a type to a variable. Useful for other people reading your code later, or not initializing a variable but not assigning it a value until later.