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.1 Syntax Support #2583

Closed
bradzacher opened this issue Sep 19, 2020 · 9 comments · Fixed by #2748
Closed

TypeScript 4.1 Syntax Support #2583

bradzacher opened this issue Sep 19, 2020 · 9 comments · Fixed by #2748
Assignees
Labels
AST PRs and Issues about the AST structure dependencies Issue about dependencies of the package has pr there is a PR raised to close this New TypeScript Version package: scope-manager Issues related to @typescript-eslint/scope-manager package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@bradzacher
Copy link
Member

bradzacher commented Sep 19, 2020

https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/

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.


Template Literal Types

type World = "world";
type Greeting = `hello ${World}`;

//

type Color = "red" | "blue";
type Quantity = "one" | "two";
type SeussFish = `${Quantity | Color} fish`;

//

type VerticalAlignment = "top" | "middle" | "bottom";
type HorizontalAlignment = "left" | "center" | "right";

// Takes
//   | "top-left"    | "top-center"    | "top-right"
//   | "middle-left" | "middle-center" | "middle-right"
//   | "bottom-left" | "bottom-center" | "bottom-right"
declare function setAlignment(value: `${VerticalAlignment}-${HorizontalAlignment}`): void;

type EnthusiasticGreeting<T extends string> = `${Uppercase<T>} - ${Lowercase<T>} - ${Capitalize<T>} - ${Uncapitalize<T>}`;
type HELLO = EnthusiasticGreeting<"heLLo">;
// same as
//   type HELLO = "HELLO - hello - Hello - heLLo";

This will require new AST nodes.

Key Remapping in Mapped Types

type MappedTypeWithNewKeys<T> = {
    [K in keyof T as NewKeyType]: T[K]
    //            ^^^^^^^^^^^^^
    //            This is the new syntax!
}

This will require AST changes.

Recursive Conditional Types

type Awaited<T> = T extends PromiseLike<infer U> ? Awaited<U> : T;

This will require no changes.

Pedantic Index Signature Checks

Example with the noUncheckedIndexedAccess compiler option turned on:

function screamLines(strs: string[]) {
    // this will have issues
    for (let i = 0; i < strs.length; i++) {
        console.log(strs[i].toUpperCase());
        //          ~~~~~~~
        // error! Object is possibly 'undefined'.
    }
}

This will require no changes (it will just start working and improve existing rules like no-unnecessary-condition for free!)

React 17 JSX Factories

This will require a slight tweak to how the parser passes options to scope-manager


Other changes that have no impact on us:

@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree dependencies Issue about dependencies of the package AST PRs and Issues about the AST structure package: scope-manager Issues related to @typescript-eslint/scope-manager labels Sep 19, 2020
@bradzacher bradzacher pinned this issue Sep 19, 2020
@aggmoulik
Copy link
Contributor

Hy @bradzacher I am working on Specs for the template literal type. If there anything you want me to consider before creating PR.

@bradzacher
Copy link
Member Author

Nothing really. Assuming it should be pretty simple to setup. I was kind of considering an AST like:

interface TSTemplateLiteralType extends Node {
  type: AST_NODE_TYPES.TemplateLiteralType;
  quasis: TemplateElement[];
  expressions: TypeNode[];
}

So that it mirrors the standard template literal.

@ranneyd
Copy link

ranneyd commented Oct 14, 2020

Status on this?

@bradzacher
Copy link
Member Author

https://github.com/typescript-eslint/typescript-eslint#supported-typescript-version
TS4.1 is still in beta, and as such is still not stable. We will not be rushing to explicitly support it for the moment.

@mauriziocarboni2
Copy link

From the Iteration plan we can see that TS4.1 will have a Release Candidate on November 3rd.

microsoft/TypeScript#40124

can we expect this issue to be fixed shortly after?

@bradzacher
Copy link
Member Author

bradzacher commented Nov 4, 2020

TS4.1 just hit RC!
https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-rc/

I'll look to filling in support soon.

@bradzacher bradzacher added the has pr there is a PR raised to close this label Nov 8, 2020
@bradzacher bradzacher self-assigned this Nov 8, 2020
bradzacher added a commit that referenced this issue Nov 8, 2020
Fixes #2583

- Adds AST for Key Remapping in Mapped Types and Template Literal Types
- Adds visitor keys for the above
- Adds scope manager support for the above (just tests were required as it all is pretty simple)
- Regenerates the scope-manager lib types
bradzacher added a commit that referenced this issue Nov 8, 2020
Fixes #2583

- Adds AST for Key Remapping in Mapped Types and Template Literal Types
- Adds visitor keys for the above
- Adds scope manager support for the above (just tests were required as it all is pretty simple)
- Regenerates the scope-manager lib types
bradzacher added a commit that referenced this issue Nov 8, 2020
Fixes #2583

- Adds AST for Key Remapping in Mapped Types and Template Literal Types
- Adds visitor keys for the above
- Adds scope manager support for the above (just tests were required as it all is pretty simple)
- Regenerates the scope-manager lib types
bradzacher added a commit that referenced this issue Nov 8, 2020
Fixes #2583

- Adds AST for Key Remapping in Mapped Types and Template Literal Types
- Adds visitor keys for the above
- Adds scope manager support for the above (just tests were required as it all is pretty simple)
- Regenerates the scope-manager lib types
bradzacher added a commit that referenced this issue Nov 8, 2020
Fixes #2583

- Adds AST for Key Remapping in Mapped Types and Template Literal Types
- Adds visitor keys for the above
- Adds scope manager support for the above (just tests were required as it all is pretty simple)
- Regenerates the scope-manager lib types
@bradzacher bradzacher unpinned this issue Nov 12, 2020
@dipasqualew
Copy link

With TypeScript 4.1 released, this issue is still closed, but I believe ESlint still breaks with:

from my package.json:

    "@typescript-eslint/eslint-plugin": "^4.8.2",
    "@typescript-eslint/parser": "^4.8.2",
    "eslint": "^7.14.0",
    "typescript": "^4.1.0"

@mlippert
Copy link

With TypeScript 4.1 released, this issue is still closed, but I believe ESlint still breaks with:

@dipasqualew,
Hmm, other than "typescript": "^4.1.2" I've got the same dependencies but it seems to work ok for me, so what is breaking for you?

Also I think the Supported Typescript Version on the readme can now be updated to state <4.2.0 instead of <4.1.0 since this tracking issue is closed, right?

@bradzacher
Copy link
Member Author

The readme is already up to date!

There are no breakages for TS4.1 - we have many passing tests.

If you think you have an issue, please file a new issue and fill out the template - as per our contributing guide.

https://github.com/typescript-eslint/typescript-eslint/blob/master/CONTRIBUTING.md

Help me to help you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2020
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 dependencies Issue about dependencies of the package has pr there is a PR raised to close this New TypeScript Version package: scope-manager Issues related to @typescript-eslint/scope-manager package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants