IT Pro is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission. Learn more

Microsoft releases TypeScript 4.6 with a score of new features

The latest iteration of the programming language brings never-before-seen features and lots of improvements to make developers' lives easier

Microsoft has released the latest version of TypeScript, version 4.6, which brings with it an array of features including some that weren’t included in the beta or release candidate (RC) versions.

Among these is the ability for developers to narrow types based on discriminate properties, something that would throw an error in previous versions of TypeScript.

Microsoft said it comes down to each developer’s preference and how they like to destructure objects into properties. 

“When destructuring individual properties into a const declaration, or when destructuring a parameter into variables that are never assigned to, TypeScript will check for if the destructured type is a discriminated union,” said Daniel Rosenwasser, senior program manager of TypeScript at Microsoft. “If it is, TypeScript can now narrow the types of variables depending on checks of other variables.”

Another of the never-before-seen features in TypeScript 4.6 is the support for es2022 in TypeScript’s --target option. It means features like class fields now have a stable output target where they can be preserved.

It also means more recently added TypeScript functionality like the at() method on arrays, Object.hasOwn, or the ‘cause’ option on a new Error can be used with the new --target setting or with --lib es2022.

A feature that was present in the previous RC release but went undocumented was the suggestions for mismatched JSDoc parameter names. Developers can document parameters using an @param tag but when these fall out of date TypeScript editors will now provide suggestions for when parameter names don’t match between a function and its JSDoc comment.

One change from the beta that made it to the current release is the removal of unnecessary arguments when programming in --jsx react-jsx mode. When compiling certain code, JavaScript would produce code containing a ‘void 0’ argument that simply wasn’t necessary. Overall bundle sizes can be reduced as a result of the argument’s removal, said Rosenwasser.

Further code improvements have been made to classes; developers will now be able to write their constructor’s code before declaring super(). 

Classes made JavaScript, a language on which TypeScript builds, require the developer to call super() before referring to ‘this’. The rule used to apply to TypeScript too but Rosenwasser said the langauge was too strict in how it enforced the rule - it was a “cheap” implementation that rejected a lot of valid code.

There are a host of other changes brought to TypeScript including, but not limited to, an expansion of binding errors in JavaScript files. The full release notes can be found on Microsoft’s TypeScript developer blog.

Featured Resources

Activation playbook: Deliver data that powers impactful, game-changing campaigns

Bringing together data and technology to drive better business outcomes

Free Download

In unpredictable times, a data strategy is key

Data processes are crucial to guide decisions and drive business growth

Free Download

Achieving resiliency with Everything-as-a-Service (XAAS)

Transforming the enterprise IT landscape

Free Download

What is contextual analytics?

Creating more customer value in HR software applications

Free Download

Recommended

Microsoft launches low-code Power Pages for 'intuitive' web development
web development

Microsoft launches low-code Power Pages for 'intuitive' web development

24 May 2022
Windows 11's nifty new search feature has one major downside
Microsoft Windows

Windows 11's nifty new search feature has one major downside

23 May 2022
Microsoft says it's provided over $100 million in tech support to Ukrainian government
cyber attacks

Microsoft says it's provided over $100 million in tech support to Ukrainian government

20 May 2022
Microsoft to double salary budget to retain workers
Careers & training

Microsoft to double salary budget to retain workers

17 May 2022

Most Popular

Open source packages with millions of installs hacked to harvest AWS credentials
hacking

Open source packages with millions of installs hacked to harvest AWS credentials

24 May 2022
Europe's first autonomous petrol station opens in Lisbon
automation

Europe's first autonomous petrol station opens in Lisbon

23 May 2022
Nvidia pauses hiring to help cope with inflation
Careers & training

Nvidia pauses hiring to help cope with inflation

23 May 2022