Fix extract type crash (#47136)

This commit is contained in:
Andrew Branch
2021-12-13 10:39:34 -08:00
committed by GitHub
parent 06746efbd9
commit 430599722e
2 changed files with 12 additions and 2 deletions

View File

@@ -145,8 +145,8 @@ namespace ts.refactor {
if (isTypeReferenceNode(node)) {
if (isIdentifier(node.typeName)) {
const symbol = checker.resolveName(node.typeName.text, node.typeName, SymbolFlags.TypeParameter, /* excludeGlobals */ true);
if (symbol?.declarations) {
const declaration = cast(first(symbol.declarations), isTypeParameterDeclaration);
const declaration = tryCast(symbol?.declarations?.[0], isTypeParameterDeclaration);
if (declaration) {
if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
pushIfUnique(result, declaration);
}

View File

@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
//// import {Renderer} from '';
////
//// export class X {
//// constructor(renderer: /**/[|Renderer|]) {}
//// }
goTo.selectRange(test.ranges()[0]);
verify.refactorAvailable("Extract type", "Extract to type alias");