@@ -5441,7 +5441,8 @@ module ts {
5441
5441
// Grammar checking
5442
5442
checkGrammarObjectLiteralExpression(node);
5443
5443
5444
- var properties: SymbolTable = {};
5444
+ var propertiesTable: SymbolTable = {};
5445
+ var propertiesArray: Symbol[] = [];
5445
5446
var contextualType = getContextualType(node);
5446
5447
var typeFlags: TypeFlags;
5447
5448
@@ -5486,34 +5487,39 @@ module ts {
5486
5487
}
5487
5488
5488
5489
if (!hasDynamicName(memberDecl)) {
5489
- properties [member.name] = member;
5490
+ propertiesTable [member.name] = member;
5490
5491
}
5492
+ propertiesArray.push(member);
5491
5493
}
5492
5494
5493
5495
// If object literal is contextually (but not inferentially) typed, copy missing optional properties from
5494
5496
// the contextual type such that the resulting type becomes a subtype in cases where only optional properties
5495
5497
// were omitted. There is no need to create new property objects as nothing in them needs to change.
5496
5498
if (contextualType && !isInferentialContext(contextualMapper)) {
5497
5499
forEach(getPropertiesOfObjectType(contextualType), p => {
5498
- if (p.flags & SymbolFlags.Optional && !hasProperty(properties , p.name)) {
5499
- properties [p.name] = p;
5500
+ if (p.flags & SymbolFlags.Optional && !hasProperty(propertiesTable , p.name)) {
5501
+ propertiesTable [p.name] = p;
5500
5502
}
5501
5503
});
5502
5504
}
5503
5505
5504
5506
var stringIndexType = getIndexType(IndexKind.String);
5505
5507
var numberIndexType = getIndexType(IndexKind.Number);
5506
- var result = createAnonymousType(node.symbol, properties , emptyArray, emptyArray, stringIndexType, numberIndexType);
5508
+ var result = createAnonymousType(node.symbol, propertiesTable , emptyArray, emptyArray, stringIndexType, numberIndexType);
5507
5509
result.flags |= (typeFlags & TypeFlags.Unwidened);
5508
5510
return result;
5509
5511
5510
5512
function getIndexType(kind: IndexKind) {
5511
5513
if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) {
5512
5514
var propTypes: Type[] = [];
5513
- for (var i = 0; i < node.properties .length; i++) {
5515
+ for (var i = 0; i < propertiesArray .length; i++) {
5514
5516
var propertyDecl = node.properties[i];
5515
5517
if (kind === IndexKind.String || isNumericName(propertyDecl.name)) {
5516
- var type = getTypeOfSymbol(getSymbolOfNode(propertyDecl));
5518
+ // Do not call getSymbolOfNode(propertyDecl), as that will get the
5519
+ // original symbol for the node. We actually want to get the symbol
5520
+ // created by checkObjectLiteral, since that will be appropriately
5521
+ // contextually typed and resolved.
5522
+ var type = getTypeOfSymbol(propertiesArray[i]);
5517
5523
if (!contains(propTypes, type)) {
5518
5524
propTypes.push(type);
5519
5525
}
0 commit comments