fix(40609): fix crash for extracting type alias with several type arguments (#40820)

This commit is contained in:
Alex T
2020-09-29 09:12:15 +03:00
committed by GitHub
parent 43b5fec3c0
commit 335ed915f1
3 changed files with 45 additions and 1 deletions

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
////type Foo<T> = {
//// 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<T> = (x: `${keyof T}Foo`, callback: (y: keyof T) => void) => void;",
"",
"type Foo<T> = {",
" fn:",
" keyof T extends string",
" ? NewType<T>",
" : never;",
"}"
].join("\n"),
});

View File

@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
////type Foo<T1, T2, T3> = {
//// 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<T1, T2, T3> = (a: T1, b: T2, c: T3, a1: T1, a2: T2, a3: T3) => void;",
"",
"type Foo<T1, T2, T3> = {",
" fn: NewType<T1, T2, T3>;",
"}"
].join("\n"),
});