DEV Community

Discussion on: Explain Typescript, I'm Like Five

Collapse
 
nepalilab profile image
Nepali Lab

TypeScript is a superscript of JS, meaning it consists of everything JS has and also has other features that JS is missing.

The major attraction of TS is that it's a strongly-typed language, means you have to define what the data-types of the variables you use.
For ex: JS is a dynamically typed language means you can literally write var testVar= 5 and JS would understand that it is Integer. Or you can just write var testVar="5" and it will unserstand that it is a string.

However, JS faced many difficulties while the values were being returned and programmers had to deal a lot on what kind of data-type the given variable was. As you can see, testVar could've been an Integer or a String. On big program structure, it's not very efficient to keep searcing what these variables were, especially if it was written by other developers. Also, it created a lot of bugs in the program because you know, instead of returning an integer, the program may return a String and it makes your development much more difficult. The error isn't seen in run-time so as you may have already guessed by now, in large projects these small problems were difficult to manage.

That's where TS comes in. You strongly define what variable you set and then once you set it, you cannot just put any random values on it. Meaning, if you set varNum as an Integer in your program, you cannot put a length of text in that variable and the compiler shows error at the run-time which is pretty useful.

Also you can make use of Interface to document as you go. For ex: if you have an entity like USER, and you want to define it you could do it this way :

Interface User {
uName : String;
uId:Number,
user_test:any

}

So, what this does is now if you create a new user, it must always have uName as a string, uId as a Number and user_test as any (number,string). So, this is very useful in developing large scale applications.

I hope I made my points clear.

Collapse
 
sasicodes profile image
Sasidharan

Thanks, man.I'm 10 now.