News

What's New in TypeScript 4.8

Microsoft released TypeScript 4.8 with a host of new features ranging from Find All References improvements to the ability to exclude specific files from auto-imports.

TypeScript, which as its name suggests is a strongly typed language along with being a strict syntactical superset of JavaScript, builds on the non-typed JavaScript by adding the ability to use optional static typing. It has been on a roll lately, recently cracking the top 10 in IEEE's language popularity ranking, while also seeing an explosion in job postings and vaulting past Java to crack the Stack Overflow top five languages.

TypeScript in a Nutshell
[Click on image for larger view.] TypeScript in a Nutshell (source: Microsoft).

Here's a summary of what's new in v4.8, along with links for more information.

  • Improved Intersection Reduction, Union Compatibility, and Narrowing: Here there are numerous seemingly small changes that nevertheless "represent fixes for many many paper cuts that have been reported over several years," Microsoft said, highlighting how --strictNullChecks received a series of correctness and consistency improvements that affect how intersection and union types work.
  • Improved Inference for infer Types in Template String Types: This affects a recently introduced new way to add extends constraints to infer type variables in conditional types.
  • --build, --watch, and --incremental Performance Improvements: Here the team introduced several optimizations designed to speed up code dealing with --watch and --incremental that, along with optimizations for project references builds using --build, reportedly cut down processing time of common operations by 10 percent to 25 percent in certain scenarios.
  • Errors When Comparing Object and Array Literals: Here, Microsoft's Daniel Rosenwasser in an Aug. 25 blog post compared the == operator used in many other languages (but not JavaScript) to check on value equality on objects, noting that in Python the == can be used to check if a list is empty by checking if a value is equal to an empty list, for example. He used this code as an example:
    if people_at_home == []:
        print("here's where I lie, broken inside. </3")
        adopt_animals()

    "This is not the case in JavaScript, where == and === between objects (and therefore, arrays) check whether both references point to the same value. We believe that similar code in JavaScript is at best an early foot-gun for JavaScript developers, and at worst a bug in production code." Thus TypeScript no longer allows code like this:

    if (peopleAtHome === []) {
    //  ~~~~~~~~~~~~~~~~~~~
    // This condition will always return 'false' since JavaScript compares objects by reference, not value.
        console.log("here's where I lie, broken inside. </3")
        adoptAnimals();
    }
  • Improved Inference from Binding Patterns: This affects how TypeScript will pick up a type from a binding pattern to make better inferences in certain cases, based on this pull request to "Limit type argument inference from binding patterns."
  • File-Watching Fixes (Especially Across git checkouts): This fixes a longtime bug where TypeScript had difficulty with some file changes in --watch mode and editor scenarios.
  • Find-All-References Performance Improvements: Developers running this command see improved functionality when aggregating references. "This reduced the amount of time TypeScript took to search a widely-used identifier in its own codebase by about 20 percent," Rosenwasser said.
  • Exclude Specific Files from Auto-Imports: Rosenwasser said this self-explanatory functionality can be useful in cases where developers can’t avoid having certain modules or libraries in a compilation but rarely want to import from them. "These modules might have lots of exports that can pollute the auto-imports list and make it harder to navigate, and this option can help in those situations."

Rosenwasser also detailed many correctness fixes and breaking changes, along with pointing to what's coming up in v4.9 in November, explained in detail in the TypeScript 4.9 Iteration Plan.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Microsoft Revamps Fledgling AutoGen Framework for Agentic AI

    Only at v0.4, Microsoft's AutoGen framework for agentic AI -- the hottest new trend in AI development -- has already undergone a complete revamp, going to an asynchronous, event-driven architecture.

  • IDE Irony: Coding Errors Cause 'Critical' Vulnerability in Visual Studio

    In a larger-than-normal Patch Tuesday, Microsoft warned of a "critical" vulnerability in Visual Studio that should be fixed immediately if automatic patching isn't enabled, ironically caused by coding errors.

  • Building Blazor Applications

    A trio of Blazor experts will conduct a full-day workshop for devs to learn everything about the tech a a March developer conference in Las Vegas keynoted by Microsoft execs and featuring many Microsoft devs.

  • Gradient Boosting Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the gradient boosting regression technique, where the goal is to predict a single numeric value. Compared to existing library implementations of gradient boosting regression, a from-scratch implementation allows much easier customization and integration with other .NET systems.

  • Microsoft Execs to Tackle AI and Cloud in Dev Conference Keynotes

    AI unsurprisingly is all over keynotes that Microsoft execs will helm to kick off the Visual Studio Live! developer conference in Las Vegas, March 10-14, which the company described as "a must-attend event."

Subscribe on YouTube