Skip to content

Commit 30e678c

Browse files
committed
fix(40609): fix crash for extracting type alias with several type arguments
1 parent dc4ccc7 commit 30e678c

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/services/refactors/extractType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace ts.refactor {
140140
if (symbol) {
141141
const declaration = cast(first(symbol.declarations), isTypeParameterDeclaration);
142142
if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
143-
result.push(declaration);
143+
pushIfUnique(result, declaration);
144144
}
145145
}
146146
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////type Foo<T> = {
4+
//// fn:
5+
//// keyof T extends string
6+
//// ? /*a*/(x: `${keyof T}Foo`, callback: (y: keyof T) => void) => void/*b*/
7+
//// : never;
8+
////}
9+
10+
goTo.select("a", "b");
11+
edit.applyRefactor({
12+
refactorName: "Extract type",
13+
actionName: "Extract to type alias",
14+
actionDescription: "Extract to type alias",
15+
newContent: [
16+
"type /*RENAME*/NewType<T> = (x: `${keyof T}Foo`, callback: (y: keyof T) => void) => void;",
17+
"",
18+
"type Foo<T> = {",
19+
" fn:",
20+
" keyof T extends string",
21+
" ? NewType<T>",
22+
" : never;",
23+
"}"
24+
].join("\n"),
25+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////type Foo<T1, T2, T3> = {
4+
//// fn: /*a*/(a: T1, b: T2, c: T3, a1: T1, a2: T2, a3: T3) => void;/*b*/
5+
////}
6+
7+
goTo.select("a", "b");
8+
edit.applyRefactor({
9+
refactorName: "Extract type",
10+
actionName: "Extract to type alias",
11+
actionDescription: "Extract to type alias",
12+
newContent: [
13+
"type /*RENAME*/NewType<T1, T2, T3> = (a: T1, b: T2, c: T3, a1: T1, a2: T2, a3: T3) => void;",
14+
"",
15+
"type Foo<T1, T2, T3> = {",
16+
" fn: NewType<T1, T2, T3>;",
17+
"}"
18+
].join("\n"),
19+
});

0 commit comments

Comments
 (0)