Skip to content

Commit 50892ac

Browse files
committed
Address CR feedback
1 parent c97dfff commit 50892ac

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/compiler/checker.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,11 +2671,6 @@ namespace ts {
26712671
// Handle exports.p = expr or this.p = expr or className.prototype.method = expr
26722672
return links.type = checkExpressionCached((<BinaryExpression>declaration.parent).right);
26732673
}
2674-
else {
2675-
// Declaration for className.prototype in inferred JS class
2676-
const type = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, undefined, undefined);
2677-
return links.type = type;
2678-
}
26792674
}
26802675
// Handle variable, parameter or property
26812676
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
@@ -6908,7 +6903,7 @@ namespace ts {
69086903
.expression as PropertyAccessExpression) // x.prototype
69096904
.expression; // x
69106905
const classSymbol = checkExpression(className).symbol;
6911-
if (classSymbol.members) {
6906+
if (classSymbol && classSymbol.members) {
69126907
return createAnonymousType(undefined, classSymbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
69136908
}
69146909
}
@@ -9635,6 +9630,14 @@ namespace ts {
96359630
return links.resolvedSignature;
96369631
}
96379632

9633+
function getInferredClassType(symbol: Symbol) {
9634+
const links = getSymbolLinks(symbol);
9635+
if (!links.inferredClassType) {
9636+
links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
9637+
}
9638+
return links.inferredClassType;
9639+
}
9640+
96389641
/**
96399642
* Syntactically and semantically checks a call or new expression.
96409643
* @param node The call/new expression to be checked.
@@ -9661,7 +9664,7 @@ namespace ts {
96619664
// in a JS file
96629665
const funcSymbol = checkExpression(node.expression).symbol;
96639666
if (funcSymbol && funcSymbol.members && (funcSymbol.flags & SymbolFlags.Function)) {
9664-
return createAnonymousType(undefined, funcSymbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
9667+
return getInferredClassType(funcSymbol);
96659668
}
96669669
else if (compilerOptions.noImplicitAny) {
96679670
error(node, Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,7 @@ namespace ts {
19971997
type?: Type; // Type of value symbol
19981998
declaredType?: Type; // Type of class, interface, enum, type alias, or type parameter
19991999
typeParameters?: TypeParameter[]; // Type parameters of type alias (undefined if non-generic)
2000+
inferredClassType?: Type; // Type of an inferred ES5 class
20002001
instantiations?: Map<Type>; // Instantiations of generic type alias (undefined if non-generic)
20012002
mapper?: TypeMapper; // Type mapper for instantiation alias
20022003
referenced?: boolean; // True if alias symbol has been referenced as a value

0 commit comments

Comments
 (0)