Paul Krill
Editor at Large

TypeScript 5.0 rebuilt to use ECMAScript modules

news
Mar 14, 20232 mins

With TypeScript 5.0, the TypeScript development team has restructured the entire codebase to use ECMAScript modules, reducing package size and improving performance.

multi color neon number 5 top five
Credit: Getty Images

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

Users of TypeScript 5.0, which currently is in a release candidate stage, will need to run Node.js 12 at a minimum. In return, npm installs promise to execute a little faster and take up less space, with the typescript package sized reduced by roughly 46%, Microsoft said in a March 9 bulletin. TypeScript too will be faster, with build times cut by 10% to 25%. API consumers of TypeScript likely will be unaffected.

TypeScript will not be shipping its API as ES modules yet. A CommonJS-authored API still will be provided, and existing build scripts will still work.

Providing background on the transition, Microsoft said the current TypeScript codebase predates ECMAScript modules, which were standardized in 2015. Not knowing how compatible ES modules would be with other module systems such as CommonJS, and not seeing a huge benefit for authoring in modules at the time, TypeScript instead used namespaces, formerly called internal modules.

Although namespaces had useful features like scopes that could merge across files, making it easy to break up a project across files and expose it as a single variable, most modern JavaScript and TypeScript code is authored using modules. Thus, by using namespaces, TypeScript’s builders weren’t using TypeScript the way most of their users are—and missing out on that experience. Namespaces also brought runtime performance issues.

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

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author