@@ -144,11 +144,20 @@ namespace ts.refactor {
144144 function visitor ( node : Node ) : true | undefined {
145145 if ( isTypeReferenceNode ( node ) ) {
146146 if ( isIdentifier ( node . typeName ) ) {
147- const symbol = checker . resolveName ( node . typeName . text , node . typeName , SymbolFlags . TypeParameter , /* excludeGlobals */ true ) ;
148- const declaration = tryCast ( symbol ?. declarations ?. [ 0 ] , isTypeParameterDeclaration ) ;
149- if ( declaration ) {
150- if ( rangeContainsSkipTrivia ( statement , declaration , file ) && ! rangeContainsSkipTrivia ( selection , declaration , file ) ) {
151- pushIfUnique ( result , declaration ) ;
147+ const typeName = node . typeName ;
148+ const symbol = checker . resolveName ( typeName . text , typeName , SymbolFlags . TypeParameter , /* excludeGlobals */ true ) ;
149+ for ( const decl of symbol ?. declarations || emptyArray ) {
150+ if ( isTypeParameterDeclaration ( decl ) && decl . getSourceFile ( ) === file ) {
151+ // skip extraction if the type node is in the range of the type parameter declaration.
152+ // function foo<T extends { a?: /**/T }>(): void;
153+ if ( decl . name . escapedText === typeName . escapedText && rangeContainsSkipTrivia ( decl , selection , file ) ) {
154+ return true ;
155+ }
156+
157+ if ( rangeContainsSkipTrivia ( statement , decl , file ) && ! rangeContainsSkipTrivia ( selection , decl , file ) ) {
158+ pushIfUnique ( result , decl ) ;
159+ break ;
160+ }
152161 }
153162 }
154163 }
0 commit comments