diff --git a/changelog_unreleased/typescript/12896.md b/changelog_unreleased/typescript/12896.md index 263f0e5c642f..d1b07bd0dcc4 100644 --- a/changelog_unreleased/typescript/12896.md +++ b/changelog_unreleased/typescript/12896.md @@ -1,4 +1,4 @@ -#### [HIGHLIGHT]Support TypeScript 4.7 (#12896, #12897, #12898, #12900 by @sosukesuzuki) +#### [HIGHLIGHT]Support TypeScript 4.7 (#12896, #12897, #12898, #12900, #12921, #12924 by @sosukesuzuki) Support [TypeScript 4.7](https://devblogs.microsoft.com/typescript/announcing-typescript-4-7) new features! diff --git a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap index 484b3ac0d6b3..0bab1a843387 100644 --- a/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap @@ -184,339 +184,19 @@ type Foo = ================================================================================ `; -exports[`ts-4.7-infer-extends.ts format 1`] = ` -====================================options===================================== -parsers: ["babel-ts"] -printWidth: 80 - | printWidth -=====================================input====================================== -type X3 = T extends [infer U extends number] ? MustBeNumber : never; -type X4 = T extends [infer U extends number, infer U extends number] ? MustBeNumber : never; -type X5 = T extends [infer U extends number, infer U] ? MustBeNumber : never; -type X6 = T extends [infer U, infer U extends number] ? MustBeNumber : never; -type X7 = T extends [infer U extends string, infer U extends number] ? U : never; -type X8 = T extends infer U extends number ? U : T; -type X9 = T extends (infer U extends number ? U : T) ? U : T; - -=====================================output===================================== -type X3 = T extends [infer U extends number] ? MustBeNumber : never; -type X4 = T extends [infer U extends number, infer U extends number] - ? MustBeNumber - : never; -type X5 = T extends [infer U extends number, infer U] - ? MustBeNumber - : never; -type X6 = T extends [infer U, infer U extends number] - ? MustBeNumber - : never; -type X7 = T extends [infer U extends string, infer U extends number] - ? U - : never; -type X8 = T extends infer U extends number ? U : T; -type X9 = T extends (infer U extends number ? U : T) ? U : T; - -================================================================================ -`; - exports[`ts-4.7-instantiation-expression.ts format 1`] = ` ====================================options===================================== parsers: ["babel-ts"] printWidth: 80 | printWidth =====================================input====================================== -// basic -const foo = bar; - // typeof let x: typeof y.z; -// new -new A; - =====================================output===================================== -// basic -const foo = bar; - // typeof let x: typeof y.z; -// new -new A(); - -================================================================================ -`; - -exports[`ts-4.7-optional-variance.ts format 1`] = ` -====================================options===================================== -parsers: ["babel-ts"] -printWidth: 80 - | printWidth -=====================================input====================================== -type Covariant = { - x: T; -} -type Contravariant = { - f: (x: T) => void; -} -type Invariant = { - f: (x: T) => T; -} -type T10 = T; -type T11 = keyof T; -type T12 = T[K]; -type T13 = T[keyof T]; - -type Covariant1 = { - x: T; -} - -type Contravariant1 = keyof T; - -type Contravariant2 = { - f: (x: T) => void; -} - -type Invariant1 = { - f: (x: T) => T; -} - -type Invariant2 = { - f: (x: T) => T; -} -type Foo1 = { - x: T; - f: FooFn1; -} - -type Foo2 = { - x: T; - f: FooFn2; -} - -type Foo3 = { - x: T; - f: FooFn3; -} - -type T21 = T; - -interface Baz {} -interface Baz {} - -interface Parent { - child: Child | null; - parent: Parent | null; -} - -declare class StateNode { - _storedEvent: TEvent; - _action: ActionObject; - _state: StateNode; -} - -=====================================output===================================== -type Covariant = { - x: T; -}; -type Contravariant = { - f: (x: T) => void; -}; -type Invariant = { - f: (x: T) => T; -}; -type T10 = T; -type T11 = keyof T; -type T12 = T[K]; -type T13 = T[keyof T]; - -type Covariant1 = { - x: T; -}; - -type Contravariant1 = keyof T; - -type Contravariant2 = { - f: (x: T) => void; -}; - -type Invariant1 = { - f: (x: T) => T; -}; - -type Invariant2 = { - f: (x: T) => T; -}; -type Foo1 = { - x: T; - f: FooFn1; -}; - -type Foo2 = { - x: T; - f: FooFn2; -}; - -type Foo3 = { - x: T; - f: FooFn3; -}; - -type T21 = T; - -interface Baz {} -interface Baz {} - -interface Parent { - child: Child | null; - parent: Parent | null; -} - -declare class StateNode { - _storedEvent: TEvent; - _action: ActionObject; - _state: StateNode; -} - -================================================================================ -`; - -exports[`ts-4.7-optional-variance-with-jsx.tsx format 1`] = ` -====================================options===================================== -parsers: ["babel-ts"] -printWidth: 80 - | printWidth -=====================================input====================================== -// valid JSX -() => {}; - -type Covariant = { - x: T; -} -type Contravariant = { - f: (x: T) => void; -} -type Invariant = { - f: (x: T) => T; -} -type T10 = T; -type T11 = keyof T; -type T12 = T[K]; -type T13 = T[keyof T]; - -type Covariant1 = { - x: T; -} - -type Contravariant1 = keyof T; - -type Contravariant2 = { - f: (x: T) => void; -} - -type Invariant1 = { - f: (x: T) => T; -} - -type Invariant2 = { - f: (x: T) => T; -} -type Foo1 = { - x: T; - f: FooFn1; -} - -type Foo2 = { - x: T; - f: FooFn2; -} - -type Foo3 = { - x: T; - f: FooFn3; -} - -type T21 = T; - -interface Baz {} -interface Baz {} - -interface Parent { - child: Child | null; - parent: Parent | null; -} - -declare class StateNode { - _storedEvent: TEvent; - _action: ActionObject; - _state: StateNode; -} - -=====================================output===================================== -// valid JSX -() => {}; - -type Covariant = { - x: T; -}; -type Contravariant = { - f: (x: T) => void; -}; -type Invariant = { - f: (x: T) => T; -}; -type T10 = T; -type T11 = keyof T; -type T12 = T[K]; -type T13 = T[keyof T]; - -type Covariant1 = { - x: T; -}; - -type Contravariant1 = keyof T; - -type Contravariant2 = { - f: (x: T) => void; -}; - -type Invariant1 = { - f: (x: T) => T; -}; - -type Invariant2 = { - f: (x: T) => T; -}; -type Foo1 = { - x: T; - f: FooFn1; -}; - -type Foo2 = { - x: T; - f: FooFn2; -}; - -type Foo3 = { - x: T; - f: FooFn3; -}; - -type T21 = T; - -interface Baz {} -interface Baz {} - -interface Parent { - child: Child | null; - parent: Parent | null; -} - -declare class StateNode { - _storedEvent: TEvent; - _action: ActionObject; - _state: StateNode; -} - ================================================================================ `; diff --git a/tests/format/misc/typescript-babel-only/ts-4.7-instantiation-expression.ts b/tests/format/misc/typescript-babel-only/ts-4.7-instantiation-expression.ts index 7334d2dfbb81..f5e71be1f8ff 100644 --- a/tests/format/misc/typescript-babel-only/ts-4.7-instantiation-expression.ts +++ b/tests/format/misc/typescript-babel-only/ts-4.7-instantiation-expression.ts @@ -1,8 +1,2 @@ -// basic -const foo = bar; - // typeof let x: typeof y.z; - -// new -new A; diff --git a/tests/format/typescript/infer-extends/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/infer-extends/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..53d6048d8481 --- /dev/null +++ b/tests/format/typescript/infer-extends/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`basic.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type X3 = T extends [infer U extends number] ? MustBeNumber : never; +type X4 = T extends [infer U extends number, infer U extends number] ? MustBeNumber : never; +type X5 = T extends [infer U extends number, infer U] ? MustBeNumber : never; +type X6 = T extends [infer U, infer U extends number] ? MustBeNumber : never; +type X7 = T extends [infer U extends string, infer U extends number] ? U : never; +type X8 = T extends infer U extends number ? U : T; +type X9 = T extends (infer U extends number ? U : T) ? U : T; + +=====================================output===================================== +type X3 = T extends [infer U extends number] ? MustBeNumber : never; +type X4 = T extends [infer U extends number, infer U extends number] + ? MustBeNumber + : never; +type X5 = T extends [infer U extends number, infer U] + ? MustBeNumber + : never; +type X6 = T extends [infer U, infer U extends number] + ? MustBeNumber + : never; +type X7 = T extends [infer U extends string, infer U extends number] + ? U + : never; +type X8 = T extends infer U extends number ? U : T; +type X9 = T extends (infer U extends number ? U : T) ? U : T; + +================================================================================ +`; diff --git a/tests/format/misc/typescript-babel-only/ts-4.7-infer-extends.ts b/tests/format/typescript/infer-extends/basic.ts similarity index 100% rename from tests/format/misc/typescript-babel-only/ts-4.7-infer-extends.ts rename to tests/format/typescript/infer-extends/basic.ts diff --git a/tests/format/typescript/infer-extends/jsfmt.spec.js b/tests/format/typescript/infer-extends/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/format/typescript/infer-extends/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap index ce37081d8cfe..29fb2537be05 100644 --- a/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/instantiation-expression/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`basic.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// basic +const foo = bar; + +=====================================output===================================== +// basic +const foo = bar; + +================================================================================ +`; + exports[`binary-expr.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -36,3 +52,19 @@ interface Example { ================================================================================ `; + +exports[`new.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// new +new A; + +=====================================output===================================== +// new +new A(); + +================================================================================ +`; diff --git a/tests/format/typescript/instantiation-expression/basic.ts b/tests/format/typescript/instantiation-expression/basic.ts new file mode 100644 index 000000000000..6bba4f1adb49 --- /dev/null +++ b/tests/format/typescript/instantiation-expression/basic.ts @@ -0,0 +1,2 @@ +// basic +const foo = bar; diff --git a/tests/format/typescript/instantiation-expression/new.ts b/tests/format/typescript/instantiation-expression/new.ts new file mode 100644 index 000000000000..92cb2ff1b585 --- /dev/null +++ b/tests/format/typescript/instantiation-expression/new.ts @@ -0,0 +1,2 @@ +// new +new A; diff --git a/tests/format/typescript/optional-variance/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/optional-variance/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..ff238fb554f1 --- /dev/null +++ b/tests/format/typescript/optional-variance/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,285 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`basic.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type Covariant = { + x: T; +} +type Contravariant = { + f: (x: T) => void; +} +type Invariant = { + f: (x: T) => T; +} +type T10 = T; +type T11 = keyof T; +type T12 = T[K]; +type T13 = T[keyof T]; + +type Covariant1 = { + x: T; +} + +type Contravariant1 = keyof T; + +type Contravariant2 = { + f: (x: T) => void; +} + +type Invariant1 = { + f: (x: T) => T; +} + +type Invariant2 = { + f: (x: T) => T; +} +type Foo1 = { + x: T; + f: FooFn1; +} + +type Foo2 = { + x: T; + f: FooFn2; +} + +type Foo3 = { + x: T; + f: FooFn3; +} + +type T21 = T; + +interface Baz {} +interface Baz {} + +interface Parent { + child: Child | null; + parent: Parent | null; +} + +declare class StateNode { + _storedEvent: TEvent; + _action: ActionObject; + _state: StateNode; +} + +=====================================output===================================== +type Covariant = { + x: T; +}; +type Contravariant = { + f: (x: T) => void; +}; +type Invariant = { + f: (x: T) => T; +}; +type T10 = T; +type T11 = keyof T; +type T12 = T[K]; +type T13 = T[keyof T]; + +type Covariant1 = { + x: T; +}; + +type Contravariant1 = keyof T; + +type Contravariant2 = { + f: (x: T) => void; +}; + +type Invariant1 = { + f: (x: T) => T; +}; + +type Invariant2 = { + f: (x: T) => T; +}; +type Foo1 = { + x: T; + f: FooFn1; +}; + +type Foo2 = { + x: T; + f: FooFn2; +}; + +type Foo3 = { + x: T; + f: FooFn3; +}; + +type T21 = T; + +interface Baz {} +interface Baz {} + +interface Parent { + child: Child | null; + parent: Parent | null; +} + +declare class StateNode { + _storedEvent: TEvent; + _action: ActionObject; + _state: StateNode; +} + +================================================================================ +`; + +exports[`with-jsx.tsx [babel-ts] format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// valid JSX +() => {}; + +type Covariant = { + x: T; +} +type Contravariant = { + f: (x: T) => void; +} +type Invariant = { + f: (x: T) => T; +} +type T10 = T; +type T11 = keyof T; +type T12 = T[K]; +type T13 = T[keyof T]; + +type Covariant1 = { + x: T; +} + +type Contravariant1 = keyof T; + +type Contravariant2 = { + f: (x: T) => void; +} + +type Invariant1 = { + f: (x: T) => T; +} + +type Invariant2 = { + f: (x: T) => T; +} +type Foo1 = { + x: T; + f: FooFn1; +} + +type Foo2 = { + x: T; + f: FooFn2; +} + +type Foo3 = { + x: T; + f: FooFn3; +} + +type T21 = T; + +interface Baz {} +interface Baz {} + +interface Parent { + child: Child | null; + parent: Parent | null; +} + +declare class StateNode { + _storedEvent: TEvent; + _action: ActionObject; + _state: StateNode; +} + +=====================================output===================================== +// valid JSX +() => {}; + +type Covariant = { + x: T; +}; +type Contravariant = { + f: (x: T) => void; +}; +type Invariant = { + f: (x: T) => T; +}; +type T10 = T; +type T11 = keyof T; +type T12 = T[K]; +type T13 = T[keyof T]; + +type Covariant1 = { + x: T; +}; + +type Contravariant1 = keyof T; + +type Contravariant2 = { + f: (x: T) => void; +}; + +type Invariant1 = { + f: (x: T) => T; +}; + +type Invariant2 = { + f: (x: T) => T; +}; +type Foo1 = { + x: T; + f: FooFn1; +}; + +type Foo2 = { + x: T; + f: FooFn2; +}; + +type Foo3 = { + x: T; + f: FooFn3; +}; + +type T21 = T; + +interface Baz {} +interface Baz {} + +interface Parent { + child: Child | null; + parent: Parent | null; +} + +declare class StateNode { + _storedEvent: TEvent; + _action: ActionObject; + _state: StateNode; +} + +================================================================================ +`; + +exports[`with-jsx.tsx [typescript] format 1`] = ` +"Unexpected token. Did you mean \`{'>'}\` or \`>\`? (2:11) + 1 | // valid JSX +> 2 | () => {}; + | ^ + 3 | + 4 | type Covariant = { + 5 | x: T;" +`; diff --git a/tests/format/misc/typescript-babel-only/ts-4.7-optional-variance.ts b/tests/format/typescript/optional-variance/basic.ts similarity index 100% rename from tests/format/misc/typescript-babel-only/ts-4.7-optional-variance.ts rename to tests/format/typescript/optional-variance/basic.ts diff --git a/tests/format/typescript/optional-variance/jsfmt.spec.js b/tests/format/typescript/optional-variance/jsfmt.spec.js new file mode 100644 index 000000000000..a156e3b55d18 --- /dev/null +++ b/tests/format/typescript/optional-variance/jsfmt.spec.js @@ -0,0 +1,3 @@ +run_spec(__dirname, ["typescript"], { + errors: { typescript: ["with-jsx.tsx"] }, +}); diff --git a/tests/format/misc/typescript-babel-only/ts-4.7-optional-variance-with-jsx.tsx b/tests/format/typescript/optional-variance/with-jsx.tsx similarity index 100% rename from tests/format/misc/typescript-babel-only/ts-4.7-optional-variance-with-jsx.tsx rename to tests/format/typescript/optional-variance/with-jsx.tsx