Skip to content

Commit

Permalink
Cherry-pick PR #47136 into release-4.5 (#47379)
Browse files Browse the repository at this point in the history
Component commits:
e61702c Fix extract type crash

Co-authored-by: Andrew Branch <andrew@wheream.io>
  • Loading branch information
typescript-bot and andrewbranch committed Jan 12, 2022
1 parent a5ebd53 commit 0854a93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/refactors/extractType.ts
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/fourslash/extractTypeUnresolvedAlias.ts
@@ -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");

0 comments on commit 0854a93

Please sign in to comment.