Skip to content

Commit 4305997

Browse files
authored
Fix extract type crash (microsoft#47136)
1 parent 06746ef commit 4305997

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/services/refactors/extractType.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ namespace ts.refactor {
145145
if (isTypeReferenceNode(node)) {
146146
if (isIdentifier(node.typeName)) {
147147
const symbol = checker.resolveName(node.typeName.text, node.typeName, SymbolFlags.TypeParameter, /* excludeGlobals */ true);
148-
if (symbol?.declarations) {
149-
const declaration = cast(first(symbol.declarations), isTypeParameterDeclaration);
148+
const declaration = tryCast(symbol?.declarations?.[0], isTypeParameterDeclaration);
149+
if (declaration) {
150150
if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
151151
pushIfUnique(result, declaration);
152152
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// import {Renderer} from '';
4+
////
5+
//// export class X {
6+
//// constructor(renderer: /**/[|Renderer|]) {}
7+
//// }
8+
9+
goTo.selectRange(test.ranges()[0]);
10+
verify.refactorAvailable("Extract type", "Extract to type alias");

0 commit comments

Comments
 (0)