As a Javascript developer, you likely have heard of Typescript and how it is an improvement on Javascript and that you need to start using it. But, if you haven’t had any direct experience using the language, you might be asking yourself the following questions:
What is the learning curve?
What are the improvements I can expect?
Can I integrate it into my existing Javascript projects?
Well, I’m here to tell you it’s not as complicated as you might think! In this article I’ll talk about how you can start using Typescript and how it can improve the work you do.
At Nascent, we have created web and mobile applications using Node.js, web frontend frameworks, React Native, and a couple of support libraries. Throughout all of these projects I have been encouraging the Javascript developers I work with to check out Typescript for their projects to help make their lives easier. Today at Nascent our new projects always begin with Typescript, and across the industry Typescript has matured and has become widely adopted.
Even though Typescript is now our first step in a project, it’s not to say that Javascript doesn’t still have its place. I use and view Javascript as a quick and dirty tool, and Typescript as the precise and professional final evolution of Javascript. Javascript is for: when I need to make a quick node script that isn’t going to be maintained, for prototypes and PoCs that are going to iterate and mutate rapidly with a lot of hacks and have an extremely short lifetime, and for tiny personal projects that have me as the single maintainer. Anything that is going to have multiple developers, a maintenance cycle, and be used in production is now written in Typescript.
Since moving to using Typescript regularly at Nascent, we’ve found the following features to be the most beneficial, and may answer some of the questions you have about Typescript.
You already know a lot of Typescript
Typescript is a superset of Javascript, so you already know 90% of Typescript if you know Javascript and have a good fundamental understanding of it and ES6/7 features such as classes, promises, and async/await. The superset part is the special sauce that that makes it a professional and precise tool!
Improving maintainability of code and improving ease of development
Static typing (hence Typescript) is now its major draw for both production applications and library creators. Static typing’s benefits for production applications and libraries are immense and cannot be understated so I’ll say it one more time. Static typing and the compiler can warn you about errors before you even run your code and provides intelligent code completion. As the app gets more complex, the typing continues to document your code for you. New developers who come onto a project know what functions expect of them and what data belongs where. There have been multiple attempts to add typing to Javascript over the years and Typescript is an example of how to do it right.
Enhancements and extra tools for you to use
Another draw are the improvements to the OOP aspects of Javascript including member property definitions, real private declarations, interfaces, and support for generics. All of this leads to greater quality of life for the developer, with tight integration to multiple IDE’s and many frameworks providing Typescript starter kit options and libraries suppling typings.
It’s not all or nothing
The pathway to learning and integrating Typescript is very smooth thanks to Typescript’s strict syntactical matching of Javascript, Typescript’s any datatype, and the ability of the compiler to implicitly recognize untyped variables as the any type. You can begin using Typescript in an existing project by enabling implicit any. The way you write functions doesn’t change and your class definitions can stay the same, your code can even look like ES5 Javascript. You can introduce typing where it will improve maintainability and makes sense, without having to type everything in the project all at once. When you are ready, you can begin layering in Typescript’s benefits as you need them, where you need them, within old and new projects.
Powerful tools when you are ready
If Javascript is your first language and you have trepidations about new features, you aren’t forced to use them if you don’t need them. When you are ready to test the waters and learn their capabilities, the path is open for you. New features like generics can be powerful for solving or simplifying problems.
Add that special sauce
We find a place for both Typescript and Javascript at Nascent. We use Typescript’s improved maintainability and extra tools in our production apps. The libraries we’ve created are written in Typescript to help usability and maintainability of the library. Teaching Typescript to Javascript developers happens in project with no decline to their effectiveness while learning. I will continue to recommend Javascript developers to check out Typescript and encourage production app teams using Javascript to add the special sauce of Typescript :)