What is so special in TypeScript that it is being used by over 13.3M+ developer worldwide, as per GitHub statistics?
We will go through all the details of TypeScript in this blog series. I will write a small blog regularly in this series, and each blog will consist a small dose of TypeScript, which you can take on easily without getting overwhelmed of learning.
As per official website,
Do you remember the days when you were learning programming languages, and you got to know about C Programming, C++ and Java!
Well, if you have ever done programming in any one of these three programming language, you are already aware of data types.
Whenever you declare some variable, you used to specify the data type of that variable in C or C++ or Java.
But this is not it, once your code start getting complex, you will face debugging related issues. Debugging becomes trickier in dynamically typed languages, sometimes the error is random.
Typescript will not make your program faster, Typescript is meant for developers, it helps developer write clean and maintainable code.
TypeScript helps developer to avoid unintentional blind code, which is full of bugs and will start breaking once you run it in production.
How to use TypeScript?
Enough talk, we will see some code examples of TypeScript here. But before that I want to write some points which I feel important to know for any beginner.
TypeScript is not compatible with browsers. You will write your code in
.tsfiles and Typescript compiler will compile it into
.jsfile which can be easily run in any browser.
To compile Typescript code, you have to download a compiler from here.
var name = "Danger" console.log("Hello, " + name) name = 234 console.log(name)
var name: string = "Danger" console.log("Hello, " + name) name = 234 // This line will throw error console.log(name)
As you can see in the above TypeScript code, it will throw error on line no. 3, because first we have initialized the
name variable with
string using Typescript type annotation, but later we are assigning the number value to name, resulting your code into an error.
This was a basic type example of Typescript, in the next blogs we will get to know some more insights of TypeScript, like everyday types, interfaces, enums, mixins, generics, module augmentation and most importantly the usage of TypeScript into a React project.
I hope you have learned something from this blog, write your thoughts in the comments as it will help me write better blogs in future.