mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
fix(40609): fix crash for extracting type alias with several type arguments (#40820)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
tests/cases/fourslash/refactorExtractType69.ts
Normal file
25
tests/cases/fourslash/refactorExtractType69.ts
Normal 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"),
|
||||
});
|
||||
19
tests/cases/fourslash/refactorExtractType70.ts
Normal file
19
tests/cases/fourslash/refactorExtractType70.ts
Normal 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"),
|
||||
});
|
||||
Reference in New Issue
Block a user