4

TypeScript 4.8: Better Intersections Union Types

 2 years ago
source link: https://coderoasis.com/typescript-intersections-union-types/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

TypeScript 4.8: Better Intersections Union Types

Web Development • Aug 15, 2022

TypeScript 4.8, a planned upgrade to Microsoft’s strongly typed JavaScript variant, has reached the release candidate stage. The new version brings correctness and consistency improvements, along with fixes to file watching on Linux and macOS.

The TypeScript 4.8 release candidate (RC) arrived on August 11. The release is due for general availability on August 23. The RC adds support for excluding which files will be considered in auto imports.

photo-1592609931095-54a2168ae893?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fGpzfGVufDB8fHx8MTY2MDIzNTI5NA&ixlib=rb-1.2.1&q=80&w=2000

The preceding beta release, which published June 21, introduced improvements to consistency and correctness under strictNullChecks. These changes affect how intersection and union types function and are leveraged in how TypeScript narrows types. In one example, unknown is close in spirit to the union type {} | null | undefined because it accepts null, undefined, and any other type. TypeScript now recognizes this and allows assignments from unknown to {} | null | undefined. Changes in TypeScript 4.8 allow for sensible improvements in control flow and type narrowing, Microsoft said. Generic values also get narrowed.

As for the file-watching fixes, TypeScript has had a longstanding bug where the language has had a hard time with certain file changes in --watch mode and editor scenarios. Frequently, these occur on Unix systems. The situation was caused by assumptions regarding how Node.js handles rename events across file systems. File systems used by Linux and MacOS use inodes, and Node.js will attach file watchers to inodes rather than file paths. TypeScript tries to use the same watcher objects if it detects a path still exists on disk, so would end up reusing the watcher object instead of installing a new watcher at the original location, and would watch for changes at what might be an irrelevant file. TypeScript 4.8 handles these cases on inode systems properly and installs a new watcher.

Elsewhere in TypeScript 4.8:

  • Optimizations have been introduced to speed up scenarios around –-watch and --incremental, along with project references using --build.
  • Inference from binding patterns has been improved.
  • When running find-all-references in an editor, TypeScript now is smarter in aggregating references. This reduced the amount of time needed to search a widely used identifier by about 20%.
  • In a breaking change, unconstrained generics are no longer assignable to {}. In another breaking change, types cannot be imported or exported in JavaScript files.

The TypeScript 4.8 beta can be downloaded via NuGet, or via NPM using the following command:

npm install -D typescript@rc

TypeScript 4.8 follows the May 2022 release of TypeScript 4.7.

photo-1592609931095-54a2168ae893?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDN8fGpzfGVufDB8fHx8MTY1NDE0MDkwNA&ixlib=rb-1.2.1&q=80&w=2000

Article Comments


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK