What is TypeScript ?
On the 27th of April 2017 you wake to begin your morning routine, Its 4:05 am,so you don’t see it yet. No screen time till 6:00 am. Personal policy. You meditate. You work out, you make breakfast. This time you decide to slide in book reading for a little while in there. You surely haven’t done that in a while.
Its 8:00 am you haven’t checked that phone screen still. Your mind is fixed on getting to the office first. And again you don’t see it. Finally the morning meetings are over and you have your sanity back for what ? An hour? Half an hour maybe before another meeting?
Then you pick up your phone to check for what you believe is a Twitter notification. That’s when your eyes catch it.
Announcing TypeScript 2.3
Today we’re excited to bring you our latest release with TypeScript 2.3!
You wonder what in Gods name? You had just gone through fire with React/Redux, you are still grappling at Vue.js. Somehow you have figured Angular out, you did not really have a choice, you were learning on the job. No results meant no salary. And so you learnt Angular.
To justify my gut feeling about this just days after TypeScript was released by Microsoft, Angular picked it up and abandoned the plain ES6 that was another available options.
With all that being said since then a decorator proposal has appeared for ES and it seems to be quite close to what original AtScript did. But before we jump the gun here really. What is this decorator proposal ES utilizes ?
A decorator is:
- an expression
- that evaluates to a function
- that takes the target, name, and decorator descriptor as arguments
- and optionally returns a decorator descriptor to install on the target object
Read more here. But if you don’t to branch out unto another page until you are done with this article, a decorator is basically an high order function?
An high order function ‘takes in’ another funtion and when it run extends the behavior of the latter function without explicitly modifying it.
So if our function myFunction(as an higher function) here takes in a function it won’t necessary modify that function, though the output will turn out differently.
One of the first things that put me off with decorators was the ‘@’ sign. It immediately felt like I was reading another language and I know its like thar for a lot of other people too.
Either ways the ‘@` tells the parser that everything (in that block of code) after that sign is a decorator. Sounds easy now? It is simply just talking to the computer directly what is about to happen which is that a function will be decorated by another function and the results will be passed back up.
And the computer says; ‘Fine go on’ . The computer then treats that block of code as a different kind of function, a function that can do things like memoization, authentication, logging and so on.
Again I wont go deep into the details of this for now but when you think of decorators think of them as this instead
of this train wreck
Imagine you have a couple of functions you want to wrap around themselves. It would be a nightmare to code and maintain such program.
All said and done about ES6 of course you would still have to deal with typing somehow in ES. And TypeScript is a natural fit there(when it comes to typing). You can complement ES with a solution like Flow to get gradual typing after all. Maybe we’ll see two bigger camps. One for ES (Babel guys) and one for TS.
What is Static vs dynamic typing ?
Typing has always been about the variables the program. If I create a static typing language I don’t have to immediately tell the compiler that this particular integer and will always be an integer. It will be exactly what I stored in the program even If I forget while coding and changed its value by passing it to another class or something. A number of good language examples are : C, C++, Java.
This doesn’t mean anyone is inherently weak or bad. And that should be the focus.
Example of Java (Static and Strongly Typed)
There is no way the system can go wrong in evaluating the value of ‘foo’ ever.
But we know better. Especially if you follow best practices.
Example of PHP (Static and Weakly Typed)
Obviously this will lead to serious issues down the road. Terrible just terrible.
Between the two up there they are just paradigm ways of coding, it doesn’t mean Static typing is bad or Dynamic typing is good. The devil that should be your sole attention should weak and strong type languages,
Here is what you loose by not coming on a scripting language that is focused on improving the life its users.
- Generic functions & polymorphism
- Higher order functions
- Object composition
Dynamic Types Don’t Mean No Type Checks.
But what if we combined both sides of the coin, that is that thing that made C++ be C++.
- Speed: Static languages are faster
- Efficiency/Effective Static languages make the programmer more accountable. Dynamic programming sometimes creates a moral hazard, and encourages bad programming habits
And that is TypeScript!
You can delve more into Typescript. This is a very brief article talking about these tools in a very peripheral manner. You are free to Google better and deeper examinations of this topic.