BT

Facilitating the spread of knowledge and innovation in professional software development

Contribute

Topics

Choose your language

InfoQ Homepage News TypeScript 4.3 Improves Property Write Types

TypeScript 4.3 Improves Property Write Types

This item in japanese

Bookmarks

The TypeScript team announced the release of TypeScript 4.3, which improves property write types, more explicit overwriting of methods, and several other key additions.

Daniel Rosenwasser, TypeScript program manager, explains one key pain point before TypeScript 4.3:

In JavaScript, it’s pretty common for APIs to convert values that are passed in before storing them. This often happens with getters and setters too.

TypeScript 4.3 improves getting and setting properties by introducing types for reading and writing to properties. For example, a setter could accept a wider range of types, and the setter code would convert the input to the format that gets returned by the getter.

One challenge with extending classes in TypeScript would occur when an underlying base class was refactored. The class extending the base class might not be aware that the methods it was extending had changed. To alleviate this challenge, TypeScript 4.3 adds the override keyword. When specified, TypeScript makes sure that a method with the same name exists in the base class and throws an error if it does not.

TypeScript 4.3 also adds the --noImplicitOverride flag making it an error to override any method from a superclass unless the override keyword gets specified.

This TypeScript release adds to the earlier private class fields support by making it possible for methods, accessors, and static members to now have private names. TypeScript 4.3 also supports constructor parameters on abstract classes.

TypeScript 4.3 also improves its type-narrowing logic for generic values, fixing a few scenarios where TypeScript errors incorrectly.

In a few key places when writing code, the type system cares about the constraint of a type. TypeScript will grab the narrowed type of the constraint to give you the data you care about.

TypeScript 4.3 has even more improvements, including:

  • Template string type improvements
  • Always-truthy promise checks
  • static index signatures
  • Smaller .tsbuildinfo files and faster builds
  • More efficient compilation
  • Import statement autocomplete
  • Support for @link tags

With these many improvements in TypeScript 4.3, there are several breaking changes to consider when upgrading:

  • The built-in lib.d.ts now leverages Mozilla’s browser-compat-data to remove APIs that no browser implements
  • Errors on always-truthy promise checks
  • Union enums cannot be compared to arbitrary numbers

Work is already underway for TypeScript 4.4, expected in August 2021. Some of the TypeScript 4.4 release goals include Stricter Optional/Missing vs. Undefined and Node.js' ESM package exports support.

TypeScript is open-source software available under the Apache 2 license. Contributions and feedback are encouraged via the TypeScript GitHub project and should follow the TypeScript contribution guidelines and Microsoft open-source code of conduct.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.