DEV Community

`Nazir Abubakar
`Nazir Abubakar

Posted on

LEARNING ABOUT TYPESCRIPT

Image OFTYPESCRIPT

INTRODUCTION

A lot of people have been tweeting or saying use typescript, learn typescript, since I major in web development. To be honest, I was enticed by this. I also feel the need to state, we should be cautious, to not learn every new and shiny tech out there but I felt this one was going to be useful. There should be a balance in your career path. Learning what is required and what will take you to the next level.

What TypeScript Is About ?

As my interest grew, in what this language is about, I did some research on it before finally deciding on learning typescript. I need to point out, that you need to have a basic understanding of JavaScript, you can always start with typescript, but I feel it'd be a lot easier knowing JavaScript and how seeing how TypeScript improves JavaScript.

Typescript

What I understood after reading the typescript documentation, I felt JavaScript and TypeScript were in a love-hate relationship. Typescript offers all of features that are in JavaScript while including it's own system.

Simply put, TypeScript is a superset of JavaScript with static typing, that can be optional.

Types in TypeScript
As you write your code in JavaScript, your elements are given types but it doesn't checks the TypeScript checks the type of an element be it a number or string, and throughout the lifecycle of that element it's consistently checked.

Let's have a quick example

let Element1 = 2;
Element1 has a type that is generated by the value it holds, which is a number, we can also implicitly add the type to a variable.

let Element2: Boolean;
Here the type has been added and when assigning a value to Element2, it has to be Boolean. Also, I'd to say one of the important feature that's in TypeScript is type checking, yes, I've said it earlier but what do I mean by that. If we try to assign, a value of different type to Element 2, we will get an error, sometimes I feel TypeScript is screaming at me, when I do that. Let's take a look.

Element2 = "Hello";
When we do something like this, we're being warned. We get a type error.

Type 'string' is not assignable to type 'boolean'.

With JavaScript we don't get issues like this, we move all the way to production, till a fault occurs.

This prevent anomalies that could occur during production and that can be fatal. There are points when coding that the differences between JavaScript and TypeScript manifest. Such as:

-Accepting props -using Interfaces, amongst others.

N.B: I'm still learning all the use case and how to improve my code with TypeScript. My code editor warns me when my ways or method of implementation are wrong :-).

The only way to become better with TypeScript is by practicing. I hope my little note was helpful.

Top comments (0)