Menu
TypeScript 4.1 beta brings template literal types

TypeScript 4.1 beta brings template literal types

The template literal type has the same syntax as template literal strings in JavaScript except it is used in type positions

Credit: Mira DeShazer

TypeScript 4.1, a planned upgrade to Microsoft’s popular open source language that adds types to JavaScript, is now available as a beta release, featuring template literal types and a multitude of other improvements.

The template literal type has the same syntax as template literal strings in JavaScript except it is used in type positions. When used with concrete literal types, a new string literal type is produced by concatenating the contents.

Unveiled September 18, the TypeScript 4.1 beta also lets developers re-map keys in mapped types with a new as clause. This new clause lets developers leverage features like template literal types to create new property names based on old ones. Keys can be filtered by producing never, saving developers from having to use an extra Omit helper type in some cases.

A release candidate for TypeScript 4.1 is due in October. TypeScript 4.0, the current major release, arrived in August. Other capabilities in TypeScript 4.1 include:

  • With a recursive conditional types capability, some restrictions are eased on conditional types, which are now able to immediately reference themselves within their branches, making it easier to write recursive type aliases. Microsoft cautions that recursive types should be used responsibly and sparingly.
  • A new flag, --noUncheckedIndexedAccess, provides a node where every property access or indexed access is considered potentially undefined. This flag can catch out-of-bounds errors but might be noisy for a lot of code. It is not automatically enabled by the --strict flag.
  • The paths option can be used without baseUrl, to avoid an issue in which poor paths have been used by auto-imports.
  • checkJs now implies allowJs, fixing a situation in which starting a checked JavaScript project required both allowJs and checkJs, which caused friction.
  • The React 17 framework’s jsxcode and jsxscode factory functions are supported through two new options for the jsxcode compiler options react-jsx and react-jsxdev.
  • The JSDoc tag @see now has better support in editors for JavaScript and TypeScript.
  • In a breaking change, members marked as abstract can no longer be marked as async. In another breaking change, resolve parameters are no longer optional in Promise.

The TypeScript 4.1 beta can be accessed through NuGet or NPM:

npm install typescript@beta


Follow Us

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Events

Why experience is the new battleground for partners

Join us for an exclusive webinar, in association with Hewlett Packard Enterprise and Technology Services Industry Association (TSIA) and learn about the latest industry insights and how technology services continue to evolve to deliver differentiated value, and how partners can be successful in 2021 and beyond.

Featured

Slideshows

Channel kicks 2021 into gear as After Hours returns to Auckland

Channel kicks 2021 into gear as After Hours returns to Auckland

After Hours made a welcome return to the channel social calendar with a bumper crowd of partners, distributors and vendors descending on The Pantry at Park Hyatt in Auckland to kick-start 2021.

Channel kicks 2021 into gear as After Hours returns to Auckland
The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards

Hundreds of leaders from the New Zealand IT industry gathered at the Hilton in Auckland on 17 November to celebrate the finest female talent in the Kiwi channel and recognise the winners of the Reseller News Women in ICT Awards (WIICTA) 2020.

The Kiwi channel gathers for the 2020 Reseller News Women in ICT Awards
Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards

The leading female front runners of the New Zealand ICT industry joined together for the annual Reseller News Women in ICT Awards event at the Hilton in Auckland, during which hundreds of guests celebrated 13 outstanding individuals who won awards, chosen from more than 50 finalists representing over 30 organisations.

Leading female front runners honoured at the 2020 Reseller News Women in ICT Awards
Show Comments