An Introduction to TypeScript

O

Javascript is working for ages but the effort for improving its performance and correcting its flaws is always ongoing. TypeScript is one such avatar, born to create a better experience with JavaScript.

The front-end developers are always on the lookout for new ways of improving on JavaScript’s old faults, and why not as they don’t have to time to wait for things get sorted. Hence, they migrate to other options instead of fighting and wasting time with the old one. But, thankfully, TypeScript is here, and it proves to be a promising change to our favorite language that may be having a significant impact on JavaScript’s future.

What is TypeScript?

An open-source typed superset of JavaScript that compiles to plain JavaScript while still letting you write normal JavaScript if you want to. Initially created by Microsoft, now has other contributors from all around the world. It encourages a more declarative style of programming through things like interfaces and static typing (more on these later), offers modules and classes, and most importantly, integrates relatively well with popular JavaScript libraries and code. Any piece of JavaScript code is also valid in TypeScript, and this makes it very easy to migrate old JavaScript code to TypeScript.

Why TypeScript?

Of course, this question will rise up in every mind as to why one needs TypeScript, when JavaScript is alive and working fine till today. The simple answer is that because of the very open nature of the Internet and the World Wide Web, it makes it very slow for the core technologies to release new features, although the specifications have been already out there. Moreover, it takes time for all of the major browsers to integrate the new features into their engine.

How TypeScript Works?

You may ask if the browsers take time to include new features and technologies into their engine, how will they understand TypeScript then? Well, they won’t! The truth is the TypeScript tool transpires the ts code into regular JavaScript code that all browsers can understand and run, now that’s worth a shot, isn’t it?

For those who are confused about the terms ‘transpile’ and what is the difference between compilation and transpilation? Well, basically it’s a developer slang for when a tool converts some programming code to an executable machine code that a human cannot read, they say it has “compiled the code.” And on the other hand, when a tool converts some programming code into some other human-readable programming code since it is an action somewhere between “translation” and “compilation”, we say it has “transpired the code.”

TypeScript Community

TypeScript is continuing to grow and so it has a very supportive community as well to help you out with everything you need at every stage.There is a fantastic support for its syntax baked into Microsoft Visual Studio IDE and Visual Studio Code, with packages and plugins for editors like Atom, Sublime Text and Emacs readily available as well.

Conclusion

TypeScript is gaining popularity due to its interesting methods of improving JavaScript’s shortcomings by introducing a static typing system, complete with interfaces and type unions. Its this way of working helps us write safer, more legible and declarative code. It integrates well with virtually every mainstream build setup out there at the moment and even gives us the ability to create and use custom types as well. There are also a myriad IDEs and text editors that have great support for its syntax and compile process, so you can use it in your coding environment of choice with little pain or process. Its future is brighter, hence you can start using it in your projects without any fear.