News

TypeScript 3.9 Ships with Faster Compile Times

Microsoft shipped TypeScript 3.9, quickening the compile times for the increasingly popular programming language used to write software ranging from Angular and Vue to Visual Studio Code.

"TypeScript 3.9 ships with many new speed improvements," said Daniel Rosenwasser, program manager, in a May 12 blog post. "Our team has been focusing on performance after observing extremely poor editing/compilation speed with packages like material-ui and styled-components. We've dived deep here, with a series of different pull requests that optimize certain pathological cases involving large unions, intersections, conditional types, and mapped types."

Rosenwasser cited six different pull requests for the open source project that delivered the above benefits:

  • Use objects instead of closures for type mappers #36576
  • Faster exit from isTypeRelatedTo with identityRelation #36590
  • Optimize deferred type references #36607
  • Cache results of isGenericObjectType and isGenericIndexType #36622
  • Avoid expensive relationship checking in mapped type member resolution #36754
  • Reduce intersections by discriminants #36696

In specific situations, each of the above was found to reduce compile times by 5 percent to 10 percent. The aforementioned material-ui-styles (which, as its name bespeaks, provides styles base on React's Material-UI design scheme -- even if its components aren't used) enjoyed a 25 percent reduced compile time. One Microsoft developer working on the Outlook Web App (according to his LinkedIn profile) tweeted a compile time for one of his projects shrank from 26 seconds to 10 seconds, "that's with ME doing NO work but upgrading."

Quicker Compile Time
[Click on image for larger view.] Quicker Compile Time (source: Twitter).

"We also have some changes to file renaming functionality in editor scenarios," Rosenwasser said. "We heard from the Visual Studio Code team that when renaming a file, just figuring out which import statements needed to be updated could take between 5 to 10 seconds. TypeScript 3.9 addresses this issue by changing the internals of how the compiler and language service caches file lookups. While there's still room for improvement, we hope this work translates to a snappier experience for everyone!"

Several editor improvements were also made in the TypeScript compiler (which itself is written in TypeScript). The compiler not only powers the TypeScript editing experience in major code editors but also JavaScript in the Visual Studio family of editors.

Editor improvements include:

  • CommonJS Auto-Imports in JavaScript: "TypeScript now automatically detects the types of imports you're using to keep your file's style clean and consistent."
  • Code Actions Preserve Newlines: TypeScript's refactorings and quick fixes often didn't preserve newlines in code. Now, "TypeScript 3.9 does a little more work to preserve what we write."
  • Quick Fixes for Missing Return Expressions: "Thanks to a pull request from community member Wenlu Wang, TypeScript can provide a quick-fix to add missing return statements, remove curly braces, or add parentheses to arrow function bodies that look suspiciously like object literals."
  • Support for "Solution Style" tsconfig.json Files: This fixed a problem in editors identifying which configuration files certain files belong to, specifically when a tsconfig.json file just existed to reference other tsconfig.json files, such as tsconfig.shared.json, tsconfig.frontend.json and tsconfig.backend.json. "This file that really does nothing but manage other project files is often called a 'solution' in some environments. Here, none of these tsconfig.*.json files get picked up by the server, but we'd really like the language server to understand that the current .ts file probably belongs to one of the mentioned projects in this root tsconfig.json.

    "TypeScript 3.9 adds support to editing scenarios for this configuration. For more details, take a look at the pull request that added this functionality."

As we reported in coverage of the release candidate that shipped just a week before the final release, other improvements include:

  • Improvements in Inference and Promise.all: A regression problem caused by updates to the declarations of functions like Promise.all and Promise.race has been fixed.
  • // @ts-expect-error Comments: "When a line is prefixed with a // @ts-expect-error comment, TypeScript will suppress that error from being reported; but if there's no error, TypeScript will report that // @ts-expect-error wasn't necessary."
  • Uncalled Function Checks in Conditional Expressions: A previously introduced feature, uncalled function checks, to report an error when a developer has forgotten to call a function, now works with ternary conditionals (the cond ? trueExpr : falseExpr syntax).

With TypeScript 3.9 out the door, developers can get a peek into what's coming up in the 4.0 iteration plan and the Feature Roadmap.

The TypeScript 4.0 beta is set for June 19, with the final release scheduled for Aug. 18.

The roadmap lists future items including:

Investigate error messages in haiku or iambic pentameter
[Click on image for larger view.] Investigate error messages in haiku or iambic pentameter (source: Twitter).

One item of particular interest to many developers -- "Investigate error messages in haiku or iambic pentameter" -- has been languishing since being introduced in March 2018. An investigation into the delay may be forthcoming.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Hands On: New VS Code Insiders Build Creates Web Page from Image in Seconds

    New Vision support with GitHub Copilot in the latest Visual Studio Code Insiders build takes a user-supplied mockup image and creates a web page from it in seconds, handling all the HTML and CSS.

  • Naive Bayes Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the naive Bayes regression technique, where the goal is to predict a single numeric value. Compared to other machine learning regression techniques, naive Bayes regression is usually less accurate, but is simple, easy to implement and customize, works on both large and small datasets, is highly interpretable, and doesn't require tuning any hyperparameters.

  • VS Code Copilot Previews New GPT-4o AI Code Completion Model

    The 4o upgrade includes additional training on more than 275,000 high-quality public repositories in over 30 popular programming languages, said Microsoft-owned GitHub, which created the original "AI pair programmer" years ago.

  • Microsoft's Rust Embrace Continues with Azure SDK Beta

    "Rust's strong type system and ownership model help prevent common programming errors such as null pointer dereferencing and buffer overflows, leading to more secure and stable code."

  • Xcode IDE from Microsoft Archrival Apple Gets Copilot AI

    Just after expanding the reach of its Copilot AI coding assistant to the open-source Eclipse IDE, Microsoft showcased how it's going even further, providing details about a preview version for the Xcode IDE from archrival Apple.

Subscribe on YouTube

Upcoming Training Events