Microsoft recently announced the availability of TypeScript version 4.0. The developers at the tech giant claimed that this version of the language represents the next generation of TypeScript with more expressivity, productivity as well as scalability.
According to the latest Stack Overflow Developers survey 2020, it secured the second position as the most loved language and 9th position among 25 programming languages as the most commonly used programming language by the developers. In one of our articles, we discussed how TypeScript weighs over other programming languages.
The program manager of TypeScript, Daniel Rosenwasser, said in a blog post, “In our past two major versions, we looked back at some highlights that shined over the years. For TypeScript 4.0, we’re going to keep up that tradition.”
Based on the feedback by the developer’s community, TypeScript 4.0 includes many intuitive features that are focussed on boosting the performance of this language. Some of them are mentioned below-
Speed Improvements in build mode with –noEmitOnError
According to Rosenwasser, previously, compiling a program after a previous compile with errors under incremental would result in extremely slow performance when using the –noEmitOnError flag. The reason is, none of the information from the last compilation would be cached in a .tsbuildinfo file based on the –noEmitOnError flag.
But now TypeScript 4.0 changes this. The new update provides a great speed boost in these scenarios, and in turn, improves the build mode scenarios, which imply both –incremental and –noEmitOnError.
The first change is that the spreads in tuple type syntax can now be generic. This means that developers can now represent higher-order operations on tuples and arrays even when they don’t know the actual types they are operating over.
The second change is that the rest elements can occur anywhere in a tuple and not just at the end. Previously, TypeScript would issue an error, such as “A rest element must be last in a tuple type”. But with TypeScript 4.0, this restriction is now relaxed.
Variadic Tuple Types
Labelled Tuple Elements
The lack of labels on tuple positions can make them harder to use as well as harder to communicate the intent. That is why in TypeScript 4.0, tuples types can now provide labels, which will deepen the connection between parameter lists and tuple types. Overall, labelled tuples are handy when taking advantage of patterns around tuples and argument lists, along with implementing overloads in a type-safe way.
unknown on catch Clause Bindings
TypeScript has ‘type any’ by default which can sometimes cause undesirable behaviour if one is trying to prevent more errors in the error-handling code. Version 4.0 will
now let a user specify the type of catch clause variables as unknown instead. unknown is safer than any because it reminds the developers that they need to perform some sorts of type-checks before operating on the values.
Besides the features mentioned above, there are several other features added in version 4.0, such as custom JSX factories, editor improvements and more. As a cherry on the top, the TypeScript website has recently been rewritten from the ground up which was rolled out early this month.
For those who have not tried their hands on TypeScript yet, Typescript Playground is a website exclusively made for them. Playground provides you with a chance to write, share and learn TypeScript.
Rosenwasser has also mentioned that the upcoming version of TypeScript, i.e. TypeScript 4.1, is around the corner. The beta version of 4.1 is going to be released in September, while the final release will land in November this year.