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

  • 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