TypeScript 4.3 brings type specification for properties

Latest upgrade to Microsoft’s typed JavaScript also introduces an override keyword and improvements to template string types.

TypeScript 4.3 brings type specification for properties
Mira DeShazer (CC0)

TypeScript 4.3, the latest version of Microsoft’s typed superset of JavaScript, is now available as a production release. The upgrade allows developers to specify types for reading and writing to properties.

This type specification enhancement addresses a situation in which modeling APIs that convert values in TypeScript has required picking between “being precise” and “being permissive.” By being precise, developers could make reading values easier but writing them harder. By being permissive, they could make writing values easier but reading harder.

Published May 26, the production release of TypeScript 4.3 follows beta and release candidate versions. Other features in TypeScript 4.3 include:

  • The addition of an override keyword, whereby a method marked with this keyword will make sure that a method with the same name exists. When extending classes in JavaScript, the language makes it easy to override methods, but there are mistakes that can be made, such as missing renames. A noImplicitOverride flag makes it an error to override any method from a superclass unless the developer explicitly uses the override keyword.
  • Improvements to template string types, including better relating and inferring between different template string types. TypeScript now does the work to prove whether or not each part of a template string can successfully match.
  • More class elements can be given #private#names to make them truly private at runtime. In addition to properties, now methods and accessors can be given private names, as can static members.
  • Under strictNullChecks, an error will be triggered when checking whether a Promise is “truthy” in a conditional.
  • Index signatures, which allow developers to set more properties on a value than a type explicitly declares, now can be declared as static. Previously, they could only be declared on the instance side of a class.
  • When an import statement does not have a path, a list of possible imports will be provided. When developers commit a full completion, the full import statement will be completed including the path that was going to be written.
  • TypeScript now can understand @Link tags and will try to resolve declarations they link to.
  • Slightly smarter type-narrowing logic is included on generic values, allowing TypeScript to accept more patterns and sometimes catch mistakes.
  • The TypeScript language service now tries to jump to the correct file when a go-to definition on relative files is being performed, even if the file is not JavaScript.

TypeScript 4.3 can be accessed through NuGet or via NPM using the command npm install typescript. TypeScript 4.2 was published as a production release on February 23, featuring enhancements pertaining to tuple types and type aliases.

Copyright © 2021 IDG Communications, Inc.