@@ -26,7 +26,7 @@ namespace ts.GoToDefinition {
26
26
if ( ! symbol ) {
27
27
return getDefinitionInfoForIndexSignatures ( node , typeChecker ) ;
28
28
}
29
-
29
+
30
30
const calledDeclaration = tryGetSignatureDeclaration ( typeChecker , node ) ;
31
31
// Don't go to the component constructor definition for a JSX element, just go to the component definition.
32
32
if ( calledDeclaration && ! ( isJsxOpeningLikeElement ( node . parent ) && isConstructorLike ( calledDeclaration ) ) ) {
@@ -233,20 +233,24 @@ namespace ts.GoToDefinition {
233
233
}
234
234
235
235
function getDefinitionFromSymbol ( typeChecker : TypeChecker , symbol : Symbol , node : Node ) : DefinitionInfo [ ] | undefined {
236
- return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( symbol . declarations , declaration => createDefinitionInfo ( declaration , typeChecker , symbol , node ) ) ;
236
+ // There are cases when you extend a function by adding properties to it afterwards,
237
+ // we want to strip those extra properties
238
+ const filteredDeclarations = symbol . declarations . filter ( d => ! ts . isAssignmentDeclaration ( d ) || d === symbol . valueDeclaration )
239
+
240
+ return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( filteredDeclarations , declaration => createDefinitionInfo ( declaration , typeChecker , symbol , node ) ) ;
237
241
238
242
function getConstructSignatureDefinition ( ) : DefinitionInfo [ ] | undefined {
239
243
// Applicable only if we are in a new expression, or we are on a constructor declaration
240
244
// and in either case the symbol has a construct signature definition, i.e. class
241
245
if ( symbol . flags & SymbolFlags . Class && ( isNewExpressionTarget ( node ) || node . kind === SyntaxKind . ConstructorKeyword ) ) {
242
- const cls = find ( symbol . declarations , isClassLike ) || Debug . fail ( "Expected declaration to have at least one class-like declaration" ) ;
246
+ const cls = find ( filteredDeclarations , isClassLike ) || Debug . fail ( "Expected declaration to have at least one class-like declaration" ) ;
243
247
return getSignatureDefinition ( cls . members , /*selectConstructors*/ true ) ;
244
248
}
245
249
}
246
250
247
251
function getCallSignatureDefinition ( ) : DefinitionInfo [ ] | undefined {
248
252
return isCallOrNewExpressionTarget ( node ) || isNameOfFunctionDeclaration ( node )
249
- ? getSignatureDefinition ( symbol . declarations , /*selectConstructors*/ false )
253
+ ? getSignatureDefinition ( filteredDeclarations , /*selectConstructors*/ false )
250
254
: undefined ;
251
255
}
252
256
0 commit comments