TypeScript was given the award for “Most Adopted Technology” based on year-on-year growth.
TypeScript has dominated the front-end developer experience and front-end programming language market from all perspectives.
By now, you already know what TypeScript is. In today’s article, we are covering highlights of TypeScript 4.6, released on 28th February.
Microsoft shipped TypeScript 4.6 with some notable changes and performance improvements. Let’s see what TypeScript 4.6 has to offer to the software development community.
If you are not familiar with TypeScript, here is a quick introduction for you.
Types have significant importance while coding as it defines what kind of values you are using and what kind of functions you are calling.
This information saves developers from typo mistakes, missing arguments, or checking for null and undefined. This improves developer experience as developers become aware of the mistakes while compile time rather those errors cause problems at runtime.
In addition to this, TypeScript provides intelligent code completion, go-to-definition, powerful editing experience, and more.
Let’s see what has been improved and added in detail in the TypeScript 4.6 version.
With this version, TypeScript is able to narrow down the signature for a function. TypeScript now can narrow types based on a discriminated property. It will check if the destructed type is a discriminated union. If yes, it can narrow the types of variables based on checks of other variables.
Control Flow Analysis is a TypeScript feature that analyzes code to obtain the best type inference based on variable usages. This is what TypeScript is famous for – Type Inference.
Previously, it was an error to contain any code at the starting of a constructor if its containing class used any property initializers. In TypeScript 4.6, this check has become easier as it now permits other code to run before super() while still ensuring that super() executes at the top level before any reference to this.
This change now allows non-this, non-super code to be root-level statements in the constructor.
TypeScript now gives suggestions for when parameter names don’t match between your function and its JSDoc comment.
You can do this using either checkJs option or by adding a // @ts-check comment to the top of the file.
With TypeScript 4.6 version, you can get this information for TypeScript files in your editor itself.
This is one of the notable features of TypeScript 4.6.
TypeScript works with a structural type system. Thanks to improved recursion depth checks available in this new version, TypeScript is now better at handling errors caused by infinitely expanding types.
This feature saves work and time for checking type compatibility. TypeScript is no longer concerned with false positives from explicitly-written types. This improves relationship checking for recursive types in many ways.
This is a new tool available with this version to provide a more readable view of the information provided by –generateTrace flag. This information helps developers to identify some of the computationally expensive types and help diagnose issues in the TypeScript compiler.
This information is hard to read and digest. With this tool, developers will have a more readable and digestible view of this information.
TypeScript’s – – target option now supports es2022. Target allows you to specify ECMAScript target version. New built-in functionality like at() method on Arrays, Object.hasOwn, or the cause option on new Error can be used with this new – – target es2022 setting or with – – lib es2022.
Features like class fields now have a stable output target with this support for es2022.
In the previous TypeScript version, there were multiple issues related to indexed access types applied to mapped types.
This release has solved most of the problems related to this using an approach that includes distributive object types. In this release, TypeScript now can infer to indexed access types which immediately index into a mapped object type.
In TS, you can express a combination of different parameters for your use. You let the compiler know that you want an array of different combinations of parameters for your method.
For example, when you are passing arguments to function, if your first argument is a string, its second argument has to be a string. If your first argument is the string ‘number’, its second argument should be a number.
Here, arguments to func depend totally on the first argument. With this release, TypeScript can narrow parameters that depend on each other.
Removing unnecessary arguments can improve bundle sizes and that’s the reason TypeScript 4.6 dropped the void 0 arguments in react-jsx.
TypeScript 4.6 comes with other breaking changes like object rest expressions now dropping members that seem to be unspreadable on generic objects.
The TypeScript programming language is open-source software, licensed under the Apache 2 license. TypeScript has seen remarkable growth over the period of time, and developers love using it as it offers better tooling at any scale.
SPEC INDIA, as your single stop IT partner has been successfully implementing a bouquet of diverse solutions and services all over the globe, proving its mettle as a boutique ISO 9001:2015 certified IT solutions organization. With efficient project management practices, international standards to comply, flexible engagement models and superior infrastructure, SPEC INDIA is a customer’s delight. Our skilled technical resources are apt at putting thoughts in a perspective by offering value-added reads for all.