We’ve been keeping a close eye on TypeScript 2.0. The new version of Microsoft’s open-source JavaScript subset first surfaced in July. After that beta, Microsoft announced a release candidate, and now the version is generally available.
TypeScript’s roots go as far back as 2012. Since then, the subset has been evolving with new features and tools, and this has made it popular with developers across the world.
New TypeScript 2.0 Features
TypeScript 2.0 brings a number of new features with the goal of enhancing productivity, providing wider support for different languages, and improving the editing experience.
Here’s an explanation of some of the most noteworthy ones:
- “Control Flow Analysis for Types: In 2.0, we’ve started using control flow analysis to better understand what a type has to be at a given location.
- Easier Module Declarations: Now you can import any path that starts with
foo/
and TypeScript will assume it exists. You can take advantage of this if your module loader understands how to import based on a certain pattern too. Now whenever you import a path ending with!text
, TypeScript will understand that the import should be typed as astring
. - Non-nullable Types: Before TypeScript 2.0,
null
andundefined
were in the domain of every type. That meant that if you had a function that took astring
, you couldn’t be sure from the type alone of whether you actually had astring
– you might actually havenull
. In TypeScript 2.0, the new--strictNullChecks
flag changes that.string
just meansstring
andnumber
meansnumber
.
According to Microsoft, many of these changes are thanks to the dedicated community. The service has grown from 275,000 downloads a month to over 2 million. Furthermore, the GitHub project has over 2000 comments, 1500 issue logs, and code from over 150 users.
Of course, this is far from the end for TypeScript. Microsoft has ideas in the pipeline to make it easier for users to express JavaScript statically. The language service will also continue to evolve, creating a tool that is smarter and more productive than ever.
You can try out TypeScript for yourself by downloading it here.