Skip to content

fix(40609): Crash on extract to type alias #40820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/refactors/extractType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/cases/fourslash/refactorExtractType69.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions tests/cases/fourslash/refactorExtractType70.ts
Original file line number Diff line number Diff line change
@@ -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"),
});