Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript 4.4 Syntax Support #3606

Closed
bradzacher opened this issue Jul 5, 2021 · 2 comments
Closed

TypeScript 4.4 Syntax Support #3606

bradzacher opened this issue Jul 5, 2021 · 2 comments
Labels
AST PRs and Issues about the AST structure New TypeScript Version package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Milestone

Comments

@bradzacher
Copy link
Member

bradzacher commented Jul 5, 2021

https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-rc/

This issue is just to track all of the new features and their implementation state in this project.
As with all releases, we will not necessarily to support all features until closer to the full release when everything the features are stabilised.

Please be patient.


Control Flow Analysis of Aliased Conditions

function foo(arg: unknown) {
    const argIsString = typeof arg === "string";
    if (argIsString) {
        console.log(arg.toUpperCase());
        //              ~~~~~~~~~~~
        // Error! Property 'toUpperCase' does not exist on type 'unknown'.
    }
}

This requires no AST changes, and should just improve all of our rules.

Symbol Pattern and Template String Pattern Index Signatures

interface Colors {
    [sym: symbol]: number;
}

interface OptionsWithDataProps {
    // Permit any property starting with 'data-'.
    [optName: `data-${string}`]: unknown;
}

This requires no AST changes, as we already support this via TSIndexSignature > Identifier.parameters > TSTypeAnnotation.typeAnnotation. Once TS supports the syntax, we will too.

Defaulting to the unknown Type in Catch Variables (--useUnknownInCatchVariables)

try {
    executeSomeThirdPartyCode();
}
catch (err) { // err: unknown

    // Error! Property 'message' does not exist on type 'unknown'.
    console.error(err.message);

    // Works! We can narrow 'err' from 'unknown' to 'Error'.
    if (err instanceof Error) {
        console.error(err.message);
    }
}

This requires no AST changes, and in fact makes the no-implicit-any-catch obsolete!

Breaking Changes -> Abstract Properties Do Not Allow Initializers (support #3765)

abstract class C {
    abstract prop = 1;
    //       ~~~~
    // Property 'prop' cannot have an initializer because it is marked abstract.
}

We can update our AST to remove the value property from TSAbstractClassProperty.
Given that this node shares the AST structure of normal class properties - it's probably not worth updating the AST spec though.

Class Static Blocks (support #3730)

class Foo {
    static Foo.count = 0;

    // This is a static block:
    static {
        if (someCondition()) {
            Foo.count++;
        }
    }
}

This will require AST changes.

Other changes with no AST impact to us

  • Exact Optional Property Types (--exactOptionalPropertyTypes)
  • tsc --help Updates and Improvements
  • Performance Improvements
    • Faster Declaration Emit
    • Faster Path Normalization
    • Faster Path Mapping
    • Faster Incremental Builds with --strict
    • Faster Source Map Generation for Big Outputs
    • Faster --force Builds
  • Spelling Suggestions for JavaScript
  • Inlay Hints
  • Auto-Imports Show True Paths in Completion Lists
  • Breaking Changes
    • lib.d.ts Changes for TypeScript 4.4
    • More-Compliant Indirect Calls for Imported Functions
    • Using unknown in Catch Variables
    • Broader Always-Truthy Promise Checks
@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree AST PRs and Issues about the AST structure labels Jul 5, 2021
@sosukesuzuki
Copy link
Contributor

Also stage 3 Class Static Blocks will implemented in 4.4

@MichaelDeBoey
Copy link
Contributor

TypeScript v4.4 is released! 🥳🎉
https://devblogs.microsoft.com/typescript/announcing-typescript-4-4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AST PRs and Issues about the AST structure New TypeScript Version package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

No branches or pull requests

3 participants