diff --git a/src/services/refactors/extractType.ts b/src/services/refactors/extractType.ts
index bf89394118798..7f528ae245d4f 100644
--- a/src/services/refactors/extractType.ts
+++ b/src/services/refactors/extractType.ts
@@ -140,7 +140,7 @@ namespace ts.refactor {
if (symbol) {
const declaration = cast(first(symbol.declarations), isTypeParameterDeclaration);
if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
- result.push(declaration);
+ pushIfUnique(result, declaration);
}
}
}
diff --git a/tests/cases/fourslash/refactorExtractType69.ts b/tests/cases/fourslash/refactorExtractType69.ts
new file mode 100644
index 0000000000000..a8126a3f9fac2
--- /dev/null
+++ b/tests/cases/fourslash/refactorExtractType69.ts
@@ -0,0 +1,25 @@
+///
+
+////type Foo = {
+//// fn:
+//// keyof T extends string
+//// ? /*a*/(x: `${keyof T}Foo`, callback: (y: keyof T) => void) => void/*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 = (x: `${keyof T}Foo`, callback: (y: keyof T) => void) => void;",
+ "",
+ "type Foo = {",
+ " fn:",
+ " keyof T extends string",
+ " ? NewType",
+ " : never;",
+ "}"
+ ].join("\n"),
+});
diff --git a/tests/cases/fourslash/refactorExtractType70.ts b/tests/cases/fourslash/refactorExtractType70.ts
new file mode 100644
index 0000000000000..91d35a35d6108
--- /dev/null
+++ b/tests/cases/fourslash/refactorExtractType70.ts
@@ -0,0 +1,19 @@
+///
+
+////type Foo = {
+//// fn: /*a*/(a: T1, b: T2, c: T3, a1: T1, a2: T2, a3: T3) => void;/*b*/
+////}
+
+goTo.select("a", "b");
+edit.applyRefactor({
+ refactorName: "Extract type",
+ actionName: "Extract to type alias",
+ actionDescription: "Extract to type alias",
+ newContent: [
+ "type /*RENAME*/NewType = (a: T1, b: T2, c: T3, a1: T1, a2: T2, a3: T3) => void;",
+ "",
+ "type Foo = {",
+ " fn: NewType;",
+ "}"
+ ].join("\n"),
+});