@@ -111,6 +111,7 @@ import {
111
111
LabeledStatement ,
112
112
last ,
113
113
map ,
114
+ mapDefined ,
114
115
MethodDeclaration ,
115
116
Modifier ,
116
117
ModifierFlags ,
@@ -1070,12 +1071,12 @@ function extractFunctionInScope(
1070
1071
callArguments . push ( factory . createIdentifier ( name ) ) ;
1071
1072
} ) ;
1072
1073
1073
- const typeParametersAndDeclarations = arrayFrom ( typeParameterUsages . values ( ) , type => ( { type, declaration : getFirstDeclaration ( type ) } ) ) ;
1074
+ const typeParametersAndDeclarations = arrayFrom ( typeParameterUsages . values ( ) , type => ( { type, declaration : getFirstDeclarationBeforePosition ( type , context . startPosition ) } ) ) ;
1074
1075
const sortedTypeParametersAndDeclarations = typeParametersAndDeclarations . sort ( compareTypesByDeclarationOrder ) ;
1075
1076
1076
1077
const typeParameters : readonly TypeParameterDeclaration [ ] | undefined = sortedTypeParametersAndDeclarations . length === 0
1077
1078
? undefined
1078
- : sortedTypeParametersAndDeclarations . map ( t => t . declaration as TypeParameterDeclaration ) ;
1079
+ : mapDefined ( sortedTypeParametersAndDeclarations , ( { declaration } ) => declaration as TypeParameterDeclaration ) ;
1079
1080
1080
1081
// Strictly speaking, we should check whether each name actually binds to the appropriate type
1081
1082
// parameter. In cases of shadowing, they may not.
@@ -1547,13 +1548,13 @@ function getContainingVariableDeclarationIfInList(node: Node, scope: Scope) {
1547
1548
}
1548
1549
}
1549
1550
1550
- function getFirstDeclaration ( type : Type ) : Declaration | undefined {
1551
+ function getFirstDeclarationBeforePosition ( type : Type , position : number ) : Declaration | undefined {
1551
1552
let firstDeclaration ;
1552
1553
1553
1554
const symbol = type . symbol ;
1554
1555
if ( symbol && symbol . declarations ) {
1555
1556
for ( const declaration of symbol . declarations ) {
1556
- if ( firstDeclaration === undefined || declaration . pos < firstDeclaration . pos ) {
1557
+ if ( ( firstDeclaration === undefined || declaration . pos < firstDeclaration . pos ) && declaration . pos < position ) {
1557
1558
firstDeclaration = declaration ;
1558
1559
}
1559
1560
}
0 commit comments