8000 GitHub · Where software is built
[go: up one dir, main page]

Skip to content
TypeScript 4.1 Syntax Support #2583
Closed
@bradzacher

Description

@bradzacher

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:

Metadata

Metadata

Assignees

Labels

ASTPRs and Issues about the AST structureNew TypeScript VersiondependenciesIssue about dependencies of the packagehas prthere is a PR raised to close thispackage: scope-managerIssues related to @typescript-eslint/scope-managerpackage: typescript-estreeIssues related to @typescript-eslint/typescript-estree

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0