diff --git a/changelog_unreleased/typescript/10418.md b/changelog_unreleased/typescript/10418.md new file mode 100644 index 000000000..ef69e0cf0 --- /dev/null +++ b/changelog_unreleased/typescript/10418.md @@ -0,0 +1,16 @@ +#### Support TypeScript 4.2 `abstract` Construct Signatures via `babel-ts` (#10418 by @sosukesuzuki) + +Support [`abstract` Construct Signatures](https://devblogs.microsoft.com/typescript/announcing-typescript-4-2/#abstract-construct-signatures). + + +```ts +// Input +type T = abstract new () => void; + +// Prettier main +SyntaxError: Unexpected token, expected ";" (1:19) + +// Prettier stable +type T = abstract new () => void; + +``` diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index 4ba8833d2..2e8310200 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -296,6 +296,9 @@ function printTypescript(path, options, print) { case "TSConstructSignatureDeclaration": case "TSCallSignatureDeclaration": case "TSConstructorType": { + if (n.type === "TSConstructorType" && n.abstract) { + parts.push("abstract "); + } if (n.type !== "TSCallSignatureDeclaration") { parts.push("new "); } diff --git a/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap b/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap index d5e87823f..cb21485d5 100644 --- a/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap @@ -62,6 +62,27 @@ class Bar { ================================================================================ `; +exports[`ts-4.2-abstract-constructor-type.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +// typescript-estree does not support abstract constructor type yet +type T = abstract new () => void; +type T = abstract new () => void; +type T = abstract + new () => void; + +=====================================output===================================== +// typescript-estree does not support abstract constructor type yet +type T = abstract new () => void; +type T = abstract new () => void; +type T = abstract new () => void; + +================================================================================ +`; + exports[`tuple-labeled-ts.ts format 1`] = ` ====================================options===================================== parsers: ["babel-ts"] diff --git a/tests/misc/typescript-babel-only/ts-4.2-abstract-constructor-type.ts b/tests/misc/typescript-babel-only/ts-4.2-abstract-constructor-type.ts new file mode 100644 index 000000000..841d8252c --- /dev/null +++ b/tests/misc/typescript-babel-only/ts-4.2-abstract-constructor-type.ts @@ -0,0 +1,5 @@ +// typescript-estree does not support abstract constructor type yet +type T = abstract new () => void; +type T = abstract new () => void; +type T = abstract + new () => void;