Exploring Typescript Shortly
Tags: typescript, javascript, beginners, programming
Published: 2022-11-12 17:39:41


#### Introducing:
Typescript Developed by Microsoft. Typescript is a Superset of Javascript. Some Top Purpose of typescript is, When we build Enterprise or Large Scale projects, we face data type-checking related issues. Suppose we expect a number type data from a variable but if we don't get it, that can be a big issue. So Typescript Smart Intelligent System Help to handle all data type of this project for Strickly Specify them. Typescript gives a Compiler error. That means when we are writing code if the code was wrong typescript gives an error this time. Code not rendering before the solution. After Compile The typescript is given a vanilla javascript Code. That's why it Helps to Support an old browser. We also configure more and select the javascript version.
#### Installation : 
Requierd Node js
```
npm i -g typescript
npm i typescript
```
#### Variable and Function Type checking : 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezo9lbf7rwzf8h7arxao.PNG)
#### Explicity  variable with Array 
Explicit Means, when we define a variable with the let keyword but did assign a value. This time we can change the value any more and also we can define any type of data type. Typescript Explicity helps to define a variable with a fixed expected data type.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4a5zc1ilhwtr08qy1u9k.png)
#### Union Type 
Union Type Means We can fix accepted data type. Like a variable value should be a number or string. If we see the below image we can be clear about what is union type. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nyes7wxgnubkrshbm34k.PNG)
#### Dynamic Type Define
Simply when we don't know which data type set in the future into the variable. This time we can use any type which provides typescript. that helps to set any type of data like the below image.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/udykocm2vqc6y3d32usy.PNG)
#### Function Type 
Typescript's beautiful feature is function type handling. Using typescript we can define Function type when variable initialization and we can define function parameter type also function return type. Typescripts have partial power to determine automatically which type should be returned.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbnv5u3li7v83e0z2ixe.PNG)
#### Function Signatures
We can fixed data type where  variable define.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v94wj954l8o06i7of06o.png)
#### Type Aliases
Suppose if we need to use multiple types explicitly, we can use them as a variable. So that we can use it multiple times.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60b8e2nqtbb7l0t3qsfn.png)
#### Interface
Interface is an other most interesting typescript feature. when we are need to check multiple variable data type, we need to write typescript multiple time. But typescript interface helps for that. Typescript give interface feature that's why we do not write same type checking code in multiple time. Below the picture is example. And we can make it reusable inside all file using import/export. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mc5bjl4ox9yd9r3upsjz.PNG)


#### Generics Types
Sometimes we do not know which type of data comes to a variable. So it creates complexity in checking data type. That's why typescript gives another feature called Generics Type checking. It helps to check dynamic data like the below image and it also works well with the interface.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a3kswcjyb47dijcu2dtu.PNG)
#### Enum Type
Enum Type is collection of a index. we can predefine index name for easily implementation. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/um0sjow79wftsitojyu0.PNG)

#### Tuples
After defining an array within a variable, we can change a value using this array index. But we can not add or modify new data types which do not exist in this array. Because of typescripts have guess capability. Typescript Auotmetically guesses the data type, then strictly forces to use this data type.

Now if we need to fix the data type using by array index, i mean we can update or modify data following this array's existing index data type. Like the below image.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5a4l1wndzlmh8ipvpv6.PNG)

#### Working with class
Typescript works well with the class or javascript object-oriented programming. When we are using class then we can define the class constructor data type.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sjry1fnarxcoslq9wkl1.PNG)


#### Access Modifers in Class
When we create an object using a class, this object property accessibility is open. We know javascript give some modifier but typescript helps it when the type is defined we can also define the public/private access modifier. Typescript introduces a new modifier which is called read-only.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mrwd1k0nm8gautkmoqsq.PNG)