Press "Enter" to skip to content

TypeScript 5.0 rebuilt to use ECMAScript modules

TypeScript 5.0, which Microsoft will release as a production release on March 16, has been restructured around the use of ECMAScript modules, a major infrastructure change for the strongly-typed variant of JavaScript.

Users of TypeScript 5.0, which is currently in a release candidate stage, will need to be running Node.js 12 at a minimum. Instead, npm installs promises to run a little faster and take up less space, with the typescript the package size was reduced by about 46%, Microsoft said in a March 9 bulletin. TypeScript will also be faster, with compile times reduced by 10-25%. TypeScript API consumers will probably not be affected.

TypeScript won’t ship its API as ES modules yet. An API created by CommonJS will continue to be provided, and existing build scripts will continue to work.

Providing background on the transition, Microsoft said that the current TypeScript codebase predates ECMAScript modules, which were standardized in 2015. Not knowing how compatible ES modules would be with other module systems like CommonJS, and not seeing a great benefit for building modules in time, TypeScript instead used namespacesformerly called internal modules.

Although namespaces it had useful features like scopes that could be merged into files, making it easy to split a project into files and expose it as a single variable, most modern JavaScript and TypeScript code is built using modules. So by using namespaces, TypeScript developers were not using TypeScript the way most of their users do, and they were missing out on that experience. Namespaces also caused runtime performance issues.

Moving to modules allows TypeScript developers to close the experience gap with their users, speed up TypeScript development and make TypeScript faster, Microsoft said. However, although TypeScript is now written with modules, the actual JS files have not changed their format. Libraries still act like CommonJS when running in a CommonJS environment.

Also Read:  News in the fediverse | InfoWorld

Copyright © 2023 IDG Communications, Inc.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *