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

Accelerating AI modernisation with data infrastructure

Generate business value from your AI initiatives

Free Download

Recommendations for managing AI risks

Integrate your external AI tool findings into your broader security programs

Free Download

Modernise your legacy databases in the cloud

An introduction to cloud databases

Free Download

Powering through to innovation

IT agility drive digital transformation

Free Download

Recommended

Microsoft reportedly blocks Russian Windows 10 and Windows 11 downloads
Microsoft Windows

Microsoft reportedly blocks Russian Windows 10 and Windows 11 downloads

20 Jun 2022
IT Pro News in Review: UK tech raises $16bn, Microsoft acquires Miburo, largest DDoS attack mitigated
Business strategy

IT Pro News in Review: UK tech raises $16bn, Microsoft acquires Miburo, largest DDoS attack mitigated

17 Jun 2022
Proofpoint details 'dangerous' ransomware flaw in SharePoint and OneDrive
ransomware

Proofpoint details 'dangerous' ransomware flaw in SharePoint and OneDrive

17 Jun 2022
Microsoft silent patches called “a grossly irresponsible policy”
cyber security

Microsoft silent patches called “a grossly irresponsible policy”

15 Jun 2022

Most Popular

LockBit 2.0 ransomware disguised as PDFs distributed in email attacks
Security

LockBit 2.0 ransomware disguised as PDFs distributed in email attacks

27 Jun 2022
The UK's best cities for tech workers in 2022
Business strategy

The UK's best cities for tech workers in 2022

24 Jun 2022
Carnival hit with $5 million fine over cyber security violations
cyber security

Carnival hit with $5 million fine over cyber security violations

27 Jun 2022