What Is Typescript ?

What Is Typescript ?

A Beginner Series To Typescript

ยท

4 min read

I am sure you have come across the word Typescript a couple of times whether on Twitter or over the internet and have noticed many many organizations and developers using this technology and have no idea, then this blog series will help you know what Typescript is all about!

Before we begin, I would love to give you my introduction. Hi ๐Ÿ‘‹, My name is Fomonyuytar Joseph, a Junior Full Stack Developer from Cameroon, I am a 3rd Software Engineering Student at the University of Buea. This is the first blog I am writing to help me share my knowledge and a better understanding of what I learn.

WHAT IS TYPESCRIPT ?

TypeScript is an "Object Oriented programming Language which is a superset of Javascript, and offers an additional type system " , am sure you now know why it was given the name Type - Script .

Am sure you must think it is a whole new Language on its own and feel overwhelmed but if you know Javascript you can pick it up quickly because TypeScript is Javascript with just types and little features added, so this, therefore, means every Javascript code you have written is valid TypeScript code!

You can take a look at the diagram to have an overview of all that was said.

JS.png

One thing to note is that TypeScript is compiled to plain Javascript ,this is beacuse our Browsers normally don't understand typeScript but rather Javascript . TypeScript has a compiler to handle the compilation or the Babel compiler can be invoked to convert TypeScript to JavaScript.

TYPES IN TYPESCRIPT

As mentioned earlier one of the major things making TypeScript different from regular Javascript is "Type", if you are coming from a C++ or Java programming background you are already aware of what type is but if you have no idea a type is simply a classification of data whether it a number, string or boolean, etc.

The common types in TypeScript you may come across include

TypeKeyword
Numbernumber
Stringstring
Array[ ]
Booleanboolean
anyany
Voidvoid
Nullnull
Undefinedundefined

TYPE ANNOTATIONS

In TypeScript there are two ways in which we can declare our variables and assign values :

//first method
let [ identifier ] : [type-annotation ] = value;

//second method
let [ identifier ] : [type-annotation ] ;
[ identifier ] = value;

We are going to see some basic examples of how we some basic Implementation declaring of variables in TypeScript.

// String type
  let userName : string = "John"

//Number type
let userAge : number;
userAge=16

//Array of strings
let Names : string[ ] = ["John","Doe", "Will"]

//Array of number
let ages : number[ ] = [20 , 10 ,45]

//Boolean
let userStatus : boolean = true

Benefits of TypeScript

At this point, you see that there isn't so much that makes it difficult for you to be able to pick up and be able to apply in your projects ,let see some benefits of using Typescript.

  • Cross-Platform and Cross browser Compatability

  • Static Typing

  • Types make code management easier

  • Easy to Spot bugs Early

  • TypeScript is popular and trusted by the big Tech companies

Drawbacks of TypeScript

TypeScript like any other Technology will have some drawbacks despite all it benefits.

  • Required compilation

  • Typescript takes a long time to compile the code

  • Bloated code

Conclusion

The purpose of this article was to give you an overview of what TypeScript is all about. By now, you should have an idea of what TypeScript is, what makes it indifferent from Javascript, its benefits and drawbacks

Some important points to remember are:

  • TypeScript is an "Object Oriented programming Language which is a superset of Javascript, and offers an additional type system "

  • TypeScript is compiled to plain Javascript

  • Some Types include Number ,String ,Boolean etc

ย