-- online Search!

Learning TypeScript in 2020

by Ray   |   filed under Web Apps

Over the last couple of years, we have been seeing more and more developers using TypeScript. But let’s ask the question, why? And does it make sense to learn TypeScript today or are we just too late? In the following sections, let's dive into TypeScript and see why developers are hyped about and what we should do! So...sit back and relax.

My short answer would be, No we are not too late! and Yes, it makes sense! Let’s dive into TypeScript and see why other developers are so hyped about it, so sit back and relax!

TypeScript vs. JavaScript

Before we go into the details of TypeScript and JavaScript and comparing them both, let's first learn more about the interesting features TypeScript brings to the table.

A few years ago, I was skeptical into whether we would need TypeScript in the future. A few things crossed my mind here. First, there are things TypeScript brings to the table that reduce the flexibility JavaScript has historically had. Given the rapid improvements being made in JavaScript,

, it would take away a big amount of flexibility in JavaScript.

But, I was right and wrong! Wrong that TypeScript is gonna be the future of JavaScript. Right because it feels like it takes away the flexibility of JavaScript, but learned that it is a very good thing instead!

Type Checking

In JavaScript, you have data types like Object, Boolean, Array, Number, String and more. These data types aren't static to a variable. A variable can be a string at a given moment and later on changed into a boolean:

<insert code snippet>

This dynamicness is totally supported by the language. If you compare this behavior to other statically typed languages, it’s really weird. This gives JavaScript it’s flexibility. But at what cost?

If you have some experience with developing websites or web applications with JavaScript, I assume you have got a lot of errors because a method was not defined.

One of the reasons this happens is that JavaScript has no type checking out-of-the-box. So chances are high you got a lot of runtime errors while your user tries to work with it.
With TypeScript, we can solve a lot of those errors.

TypeScript prevents a lot of errors due to wrong types or types that are changing. With TypeScript you will not change types, no you make your code more predictable by keeping them as they are.

New ECMAScript Features

A lot of JavaScript projects are using Babel to use new JavaScript features that are not supported in our browsers yet. Babel compiles your code to a version that all modern browsers understand.

TypeScript does also compiles your code to JavaScript which is supported by modern browsers. If you like even older browsers, but than you are restricted to not use the most modern features in JavaScript.

TSconfig.json

Every project that is using TypeScript has a tsconfig.json file with all the settings for that project. One of the settings in the compilerOptions in which you set the target, module and a lot more.
In the target we specify which JavaScript version (ECMAScript) we want the TypeScript compiler to output. In the module we can set the module version.
With these options, we can make sure our JavaScript file is supported by modern browsers but also the older ones. It will include some polyfills in your files, so an older browser can use newer features.

ES2015

Currently, we can see that all major browsers have all implemented the ES2015 (ES6) features. So depending on your target version, TypeScript will support those features

ES2016+

If you check the ES2016+ support table, you can see that a big amount of the browsers support ES2016, ES2017, ES2018, ES2019 and even a big amount of ES2020 features.
TypeScript is supporting a great amount of them, but not all of them just like Babel.js.

What problem will TypeScript solve?

Type checking

In terms of type checking, it is a very valid idea to use TypeScript. JavaScript doesn't have a type system that you can use, so preventing errors due to types, we should use TypeScript in my opinion.

Before TypeScript we have had error's in runtime, so it could bother a lot of users. With TypeScript, we move the error sensitive time earlier in the development process. During compilation, we have errors, in this way we can prevent the user from a bad experience.

Browser support

If you would only use TypeScript for the sake of supporting older browsers while developing with the newest features, I wouldn't recommend it. Since the development of the new JavaScript features in modern browsers goes fast, we shouldn't use it only for that purpose.
Using TypeScript with the type system and fixing older browser support makes more sense to me.

Syntax flavor

Let's talk about the syntax of TypeScript. I can imagine that if you're looking to this example you find it a bit harder to read for the first time.

// Example from: https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html
interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person: Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

let user = { firstName: "Jane", lastName: "User" };

document.body.textContent = greeter(user);

It could feel like misusing the JavaScript syntax. But when you have spent some more time trying it out, it will become more natural. I can tall you this from my own experience.

Who is Using TypeScript?

TypeScript is built by Microsoft. There are a lot of companies and frameworks who are using TypeScript.

The Angular framework build by Google is using TypeScript as its main driver. For the rest, TypeScript is being supported by React, VueJS, and NodeJS.

It’s funny to mention that the official author of NodeJS is starting a new project,ย Deno. Which is an alternative to NodeJS but will support TypeScript by default.

Even in the StateOfJS, you can see theย popularity of TypeScript. So it looks like a lot of developers are interested in TypeScript and a lot of them already using it.

Conclusion

I hope that this post gave you some guidance in your decision to pick TypeScript or not. I think TypeScript will solve a lot of problems we have in JavaScript. If we look at the popularity, we can make our guesses if it is smart to bet on TypeScript for now and the future.

If you have questions around TypeScript or if it is smart to use for your project, please let me know in the comments so I can help you further.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence slop, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.

Your support keeps this site going! ๐Ÿ˜‡

Kirupa's signature!

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design ๐ŸŽจ, development ๐Ÿค–, and business ๐Ÿ’ฐ - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright KIRUPA 2026 //--