Skip to content

Commit e354aec

Browse files
committed
Mark anonymous type as resolved before resolving call signatures
1 parent 87036fe commit e354aec

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/compiler/checker.ts

+23-25
Original file line numberDiff line numberDiff line change
@@ -3608,37 +3608,29 @@ namespace ts {
36083608

36093609
function resolveAnonymousTypeMembers(type: AnonymousType) {
36103610
const symbol = type.symbol;
3611-
let members: SymbolTable;
3612-
let callSignatures: Signature[];
3613-
let constructSignatures: Signature[];
3614-
let stringIndexType: Type;
3615-
let numberIndexType: Type;
3616-
36173611
if (type.target) {
3618-
members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
3619-
callSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper, instantiateSignature);
3620-
constructSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper, instantiateSignature);
3621-
stringIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.String), type.mapper);
3622-
numberIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.Number), type.mapper);
3612+
const members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper, /*mappingThisOnly*/ false);
3613+
const callSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper, instantiateSignature);
3614+
const constructSignatures = instantiateList(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper, instantiateSignature);
3615+
const stringIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.String), type.mapper);
3616+
const numberIndexType = instantiateType(getIndexTypeOfType(type.target, IndexKind.Number), type.mapper);
3617+
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
36233618
}
36243619
else if (symbol.flags & SymbolFlags.TypeLiteral) {
3625-
members = symbol.members;
3626-
callSignatures = getSignaturesOfSymbol(members["__call"]);
3627-
constructSignatures = getSignaturesOfSymbol(members["__new"]);
3628-
stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String);
3629-
numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number);
3620+
const members = symbol.members;
3621+
const callSignatures = getSignaturesOfSymbol(members["__call"]);
3622+
const constructSignatures = getSignaturesOfSymbol(members["__new"]);
3623+
const stringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String);
3624+
const numberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number);
3625+
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
36303626
}
36313627
else {
36323628
// Combinations of function, class, enum and module
3633-
members = emptySymbols;
3634-
callSignatures = emptyArray;
3635-
constructSignatures = emptyArray;
3629+
let members = emptySymbols;
3630+
let constructSignatures: Signature[] = emptyArray;
36363631
if (symbol.flags & SymbolFlags.HasExports) {
36373632
members = getExportsOfSymbol(symbol);
36383633
}
3639-
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) {
3640-
callSignatures = getSignaturesOfSymbol(symbol);
3641-
}
36423634
if (symbol.flags & SymbolFlags.Class) {
36433635
const classType = getDeclaredTypeOfClassOrInterface(symbol);
36443636
constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]);
@@ -3651,10 +3643,16 @@ namespace ts {
36513643
addInheritedMembers(members, getPropertiesOfObjectType(baseConstructorType));
36523644
}
36533645
}
3654-
stringIndexType = undefined;
3655-
numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined;
3646+
const numberIndexType = (symbol.flags & SymbolFlags.Enum) ? stringType : undefined;
3647+
setObjectTypeMembers(type, members, emptyArray, constructSignatures, undefined, numberIndexType);
3648+
// We resolve the members before computing the signatures because a signature may use
3649+
// typeof with a qualified name expression that circularly references the type we are
3650+
// in the process of resolving (see issue #6072). The temporarily empty signature list
3651+
// will never be observed because a qualified name can't reference signatures.
3652+
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) {
3653+
(<ResolvedType>type).callSignatures = getSignaturesOfSymbol(symbol);
3654+
}
36563655
}
3657-
setObjectTypeMembers(type, members, callSignatures, constructSignatures, stringIndexType, numberIndexType);
36583656
}
36593657

36603658
function resolveStructuredTypeMembers(type: ObjectType): ResolvedType {

0 commit comments

Comments
 (0)