What is TypeScript?

A strict teacher

Let's start by smashing some Jargon!

What is a Type?

A type is a label that describes the different properties and methods that a value has TypeScript Types

What's a Superset?

A programming language that contains all the features of a given language and has been expanded or enhanced to include other features as well. Dictionary Superset

TypeScript = JavaScript + Enhanced

Alrighty Then

What is TypeScript

TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at scale. TypeScriptlang

TypeScript is a Superset of Javascript, it's used to expand and enhance upon Javascript. TypeScript(TS) is strongly typed compared to Javascript, which means that in TypeScript you can say:

X is going to be a number, you are only expected to put numbers into X

While in Javascript we can't define what X is always meant to hold.

So what we have done is define X to be a Type, and that Type in this example is a number, if we then go add a String into X instead of a number we are thrown an error in your editor and compile. This is because TypeScript is performing the core function it's made for which is checking if X is assigned the correct type.

In Javascript since it is looser, we would get no error with assigning a String to X.

Gif showing an Error screen

Why would you use TypeScript

The main reason is type checking. This allows you to create code that's easier to manage for a team to work on, as they have precise rules for what something should be, and how it should act.

It allows for an increased team understanding of the code, as it reduces ambiguity, and in a way creates "Self-documenting code" as now other developers know what X should be.

In such a small example it's easy to dismiss the use of TypeScript and say that the extra effort of defining types is just extra unneeded rules but in a larger codebase, it can add efficiency and predictability to your code.

It's easy to start with TS

You do not need to instantly convert your entire project to TS or use strict TS. You can set your editor to be very lenient with how you use your TS and it's important to remember since it only gives you the errors at compile not runtime that your TS file that's yelling at you will still be compiled to JS.

Since TS is like this, you can change your JS file to a TS file today, to get started.

There are a lot of pros and cons to Typescript, I've linked to a good article that has these examples below.

Check out TypeScript Pros Cons for a comprahensive list of benefits from TypeScript.

You can start today

Start Today, check out the get started and see how you feel

Fun videos and stuff

TypeScript Pros Cons