From 3792d9b34398360f4e3a13dc542b10c3e9c82a6c Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 30 Mar 2022 11:23:58 +0300 Subject: [PATCH] fix(48405): emit dummy members from a mapped type --- src/compiler/emitter.ts | 1 + .../cases/fourslash/refactorExtractType76.ts | 17 +++++++++++++++ .../cases/fourslash/refactorExtractType77.ts | 21 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/cases/fourslash/refactorExtractType76.ts create mode 100644 tests/cases/fourslash/refactorExtractType77.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 62d3aaf19c6af..e06b0e6b8b1dc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2370,6 +2370,7 @@ namespace ts { writeLine(); decreaseIndent(); } + emitList(node, node.members, ListFormat.PreserveLines); writePunctuation("}"); } diff --git a/tests/cases/fourslash/refactorExtractType76.ts b/tests/cases/fourslash/refactorExtractType76.ts new file mode 100644 index 0000000000000..7dc67bf84cb91 --- /dev/null +++ b/tests/cases/fourslash/refactorExtractType76.ts @@ -0,0 +1,17 @@ +/// + +// @Filename: a.ts +////type Deep = /*a*/{ [K in keyof T]: Deep }/*b*/ + +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Extract type", + actionName: "Extract to type alias", + actionDescription: "Extract to type alias", + newContent: +`type /*RENAME*/NewType = { + [K in keyof T]: Deep; +}; + +type Deep = NewType`, +}); diff --git a/tests/cases/fourslash/refactorExtractType77.ts b/tests/cases/fourslash/refactorExtractType77.ts new file mode 100644 index 0000000000000..df449726cb17e --- /dev/null +++ b/tests/cases/fourslash/refactorExtractType77.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: a.ts +////type Expand = T extends any +//// ? /*a*/{ [K in keyof T]: Expand }/*b*/ +//// : never; + +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Extract type", + actionName: "Extract to type alias", + actionDescription: "Extract to type alias", + newContent: +`type /*RENAME*/NewType = { + [K in keyof T]: Expand; +}; + +type Expand = T extends any + ? NewType + : never;`, +});