This video is available to students only

Why TypeScript?

In this lesson, we're going to look at the typescript concepts

Typescript concepts#

As we discussed earlier, we are going to use React with Typescript in this project for type safety. Why do we need it in the first place? JavaScript is a weakly typed language which means you can assign any data type to any variable and you can return anything from a function, unlike all the other programming languages. To overcome these concerns, Typescript was created. It is a strongly typed superset of Javascript that was created by Microsoft in 2012. So what does it do?

  • Prevents trivial Errors.

  • Makes Code more readable.

  • Adds static types to Javascript code.

Now let's talk about the main concept of Javascript:

Type annotation#

In TypeScript, type annotations are annotations which can be placed anywhere when we use a type. The use of Type annotation is not mandatory in TypeScript. TypeScript has ability to infer the data types. It just helps the compiler in checking the types of variable and avoiding errors when dealing with the data types. Let's talk about the any data type.

Any#

When it's impossible to figure out the data type, there is the any type. This will let you provide the variable for all available data types. We can say that all the JavaScript variables have any type. let's look at the example: x had any type which is a number 4, then we changed it to a string, "it can be a string". Finally, we gave it a boolean type, false.

Now, let's talk about the primitive data types.

Primitives#

Start a new discussion. All notification go to the author.