What is TypeScript ?
On the 27th of April 2017, you wake to begin your morning routine, It’s 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 the book reading routine for a little while in there. You surely haven’t done that in a while.
It’s 8:00 am you have managed to not have checked that phone screen. 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 is this? You had just gone through hell with React/Redux, you are still grappling at Vue.js. Somehow you have figured Angular out. Well okay let’s say you did not really have a choice, you were learning on the job. No results meant your job would suffer. And so you learned Angular.
With all that being said since then a decorator proposal has appeared for ES and it seems to be quite close to what original actionScript 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 want to branch out into another page until you are done with this article, a decorator is basically a high order function? An high order function ‘takes in’ another function and when it runs, it extends the behaviour of the latter function without explicitly modifying it.
So if our function myFunction(as a higher function) here takes in a function it won’t necessarily modify that function, though the output will turn out differently.
And the computer says; ‘Got it! Fine, go on’ . The computer then treats that block of code as a different kind of function, kind of like how a parent would treat a favourite child and as a result of this special attention from the ‘parent’, it becomes a function that can do cool things like memoization, authentication, logging and so on. Again I won’t go deeply 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 ?
Example of Java (Static and Strongly Typed)
There is no way the system can go wrong in evaluating the value of ‘foo’, ever.
Example of PHP (Static and Weakly Typed)
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 be weak and strong type languages. Here is what you lose by overlooking a scripting language that is focused on improving the life its users.
- Generic functions & Polymorphism
- Higher order functions
- Object composition
- Speed: Static languages are generally 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!
If this article makes Typescript sound interesting, you can delve more into Typescript and see if it’s something you want to invest time and energy into. This is just a very brief article talking about these tools in a very peripheral manner.
Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!