Skip to content

Commit dab0dbe

Browse files
committed
Avoid the class declaration not found assert when the new expression doesnt contain construct signature
1 parent 35450d3 commit dab0dbe

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/services/goToDefinition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ namespace ts.GoToDefinition {
191191
function getConstructSignatureDefinition(): DefinitionInfo[] | undefined {
192192
// Applicable only if we are in a new expression, or we are on a constructor declaration
193193
// and in either case the symbol has a construct signature definition, i.e. class
194-
if (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword && symbol.flags & SymbolFlags.Class) {
194+
if (symbol.flags & SymbolFlags.Class && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) {
195195
const cls = find(symbol.declarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration");
196196
return getSignatureDefinition(cls.members, /*selectConstructors*/ true);
197197
}

tests/cases/fourslash/goToDefinitionNewExpressionTargetNotClass.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
////let I: {
66
//// /*constructSignature*/new(): C2;
77
////};
8-
////let C = new [|/*invokeExpression*/I|]();
8+
////new [|/*invokeExpression1*/I|]();
9+
////let /*symbolDeclaration*/I2: {
10+
////};
11+
////new [|/*invokeExpression2*/I2|]();
912

10-
verify.goToDefinition("invokeExpression", "constructSignature");
13+
verify.goToDefinition({
14+
invokeExpression1: "constructSignature",
15+
invokeExpression2: "symbolDeclaration"
16+
});

0 commit comments

Comments
 (0)