TypeScript 4.1 released: recursive conditional types, JSX factories for React and more

TypeScript 4.1 is the next big update for the programming language. The new version is full of exciting features: This not only includes the fact that the new JSX factories from React 17 are now supported. There are also innovations in the release for different types of types.

TypeScript 4.1 is here and brings many changes: The new version of the language has numerous features in its luggage, but also includes breaking changes. As always, TypeScript does not work in the classic style of semantic versioning. Release 4.1 does not offer developers a break with regard to the possibly necessary adjustments to the code. What has changed?

TypeScript 4.1: New language features

For React developers, TypeScript 4.1 brings support for the new JSX factories. To this end, two new options have been added to the JSX compiler, which according to their names are intended for development and production: react-jsxand react-jsxdev. Better support for the JSDoc tag is now @seeavailable for working with TypeScript in editors . This should improve the usability of TypeScript 4.1.

But what has happened on the level of the eponymous types? TypeScript 4.1 of course not only includes the smaller innovations mentioned above, but also brings a lot of new language features with it. These include the new template literal types that can be used to create string literal types. The new types correspond to the syntax of the template literal strings in JavaScript, but are used in type positions. An example of this can be found in the blog post on the release of TypeScript 4.1.

Basic camp for beginners

Get a structured and comprehensible introduction to Angular. All concepts and backgrounds easily explained online!

New: Deep-Dive for advanced users

Penetrate all of Angular’s concepts. Learn about pitfalls, misunderstandings, and deliberate limitations. As online training or on-site in Düsseldorf!

There is also something new for mapped types in the release: Until now, mapped types could only create new object types if the necessary keys were already specified. With this update for TypeScript it is now also possible to reassign keys using the expression asin Mapped Types. There is also news for conditional types: Here some restrictions have been relaxed so that conditional types can now be used recursively. You can now refer to yourself within your own code section. This adaptation to the behavior of TypeScript should make it easier for developers to write recursive type aliases.

Breaking changes in v4.1

As already mentioned at the beginning, TypeScript 4.1 also brings breaking changes with it, which, unlike other tools, have an immediate effect, not only for the subsequent major release. TypeScript uses a numbering format that is reminiscent of semantic versioning, but does not follow this scheme. Every new version can bring breaking changes and major feature changes with it, the TypeScript team does not limit such interventions in the language to the versions that are numbered with a full number.

One of the breaking changes in v4.1 is, for example, that some of the APIs lib.d.tsmay have changed. Has definitely been removed Reflect.enumerate; There is no further information on the other possible adjustments in the blog post for the release, as these depend on the automatically generated DOM types in the specific project. Also listed as breaking change is that resolveat least one value must be transferred in future in promises. Previously, the parameters could be set here optionally; that is no longer the case. Code sections that use resolvewithout parameters will output an error in the future.

The new features of TypeScript 4.1 mentioned here are of course not an exhaustive list. Daniel Rosenwasser, Program Manager for TypeScript, gives an overview with explanations of all the new features in the official blog post on the release . The following version, TypeScript 4.2, is to be finally published on February 23, 2021. According to the roadmap, there are plans to introduce strict overridechecks. This is in connection with the discussion about the introduction of the keyword overridein class methods, which was initiated in 2015 . The topic was taken up again in May 2020.

Leave a Reply