@@ -2321,6 +2321,9 @@ namespace ts {
2321
2321
printFollowingPunctuation = true;
2322
2322
}
2323
2323
}
2324
+ const resolved = resolveStructuredTypeMembers(type);
2325
+ writeIndexSignature(resolved.stringIndexInfo, SyntaxKind.StringKeyword);
2326
+ writeIndexSignature(resolved.numberIndexInfo, SyntaxKind.NumberKeyword);
2324
2327
writer.decreaseIndent();
2325
2328
if (printFollowingPunctuation) {
2326
2329
writeSpace(writer);
@@ -4306,15 +4309,14 @@ namespace ts {
4306
4309
4307
4310
function resolveSpreadTypeMembers(type: SpreadType) {
4308
4311
// The members and properties collections are empty for spread types. To get all properties of an
4309
- // spread type use getPropertiesOfType (only the language service uses this) .
4310
- let stringIndexInfo: IndexInfo = undefined ;
4311
- let numberIndexInfo: IndexInfo = undefined ;
4312
+ // spread type use getPropertiesOfType.
4313
+ let stringIndexInfo: IndexInfo = getIndexInfoOfSymbol(type.symbol, IndexKind.String) ;
4314
+ let numberIndexInfo: IndexInfo = getIndexInfoOfSymbol(type.symbol, IndexKind.Number) ;
4312
4315
for (let i = type.types.length - 1; i > -1; i--) {
4313
4316
const t = type.types[i];
4314
- stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String));
4315
- numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number));
4316
- if (!t.symbol || !(t.symbol.flags & SymbolFlags.Optional)) {
4317
- break;
4317
+ if (!t.isDeclaredProperty) {
4318
+ stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String));
4319
+ numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number));
4318
4320
}
4319
4321
}
4320
4322
setObjectTypeMembers(type, emptySymbols, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
@@ -4545,6 +4547,9 @@ namespace ts {
4545
4547
result.containingType = containingType;
4546
4548
result.hasCommonType = hasCommonType;
4547
4549
result.declarations = declarations;
4550
+ if (declarations.length) {
4551
+ result.valueDeclaration = declarations[0];
4552
+ }
4548
4553
result.isReadonly = isReadonly;
4549
4554
result.type = containingType.flags & TypeFlags.Intersection ? getIntersectionType(propTypes) : getUnionType(propTypes);
4550
4555
return result;
@@ -5059,7 +5064,7 @@ namespace ts {
5059
5064
const declaration = getIndexDeclarationOfSymbol(symbol, kind);
5060
5065
if (declaration) {
5061
5066
return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType,
5062
- (getModifierFlags(declaration) & ModifierFlags.Readonly) !== 0, declaration);
5067
+ (getModifierFlags(declaration) & ModifierFlags.Readonly) !== 0, declaration);
5063
5068
}
5064
5069
return undefined;
5065
5070
}
@@ -5683,11 +5688,15 @@ namespace ts {
5683
5688
}
5684
5689
spreads.push(getTypeFromTypeNode((member as SpreadTypeElement).type) as SpreadElementType);
5685
5690
}
5686
- else if (member.kind !== SyntaxKind.CallSignature && member.kind !== SyntaxKind.ConstructSignature) {
5687
- // note that spread types don't include call and construct signatures
5691
+ else if (member.kind !== SyntaxKind.CallSignature &&
5692
+ member.kind !== SyntaxKind.ConstructSignature &&
5693
+ member.kind !== SyntaxKind.IndexSignature) {
5694
+ // note that spread types don't include call and construct signatures, and index signatures are resolved later
5688
5695
const flags = SymbolFlags.Property | SymbolFlags.Transient | (member.questionToken ? SymbolFlags.Optional : 0);
5689
5696
const text = getTextOfPropertyName(member.name);
5690
5697
const symbol = <TransientSymbol>createSymbol(flags, text);
5698
+ symbol.declarations = [member];
5699
+ symbol.valueDeclaration = member;
5691
5700
symbol.type = getTypeFromTypeNodeNoAlias((member as IndexSignatureDeclaration | PropertySignature | MethodSignature).type);
5692
5701
if (!members) {
5693
5702
members = createMap<Symbol>();
@@ -10458,7 +10467,7 @@ namespace ts {
10458
10467
}
10459
10468
else if (memberDecl.kind === SyntaxKind.SpreadElementExpression) {
10460
10469
if (propertiesArray.length > 0) {
10461
- const t = createObjectLiteralType(node, hasComputedStringProperty, hasComputedNumberProperty, propertiesArray, propertiesTable, typeFlags, patternWithComputedProperties, inDestructuringPattern ) as SpreadElementType;
10470
+ const t = createObjectLiteralType() as SpreadElementType;
10462
10471
t.isDeclaredProperty = true;
10463
10472
spreads.push(t);
10464
10473
propertiesArray = [];
@@ -10510,7 +10519,7 @@ namespace ts {
10510
10519
10511
10520
if (spreads.length > 0) {
10512
10521
if (propertiesArray.length > 0) {
10513
- const t = createObjectLiteralType(node, hasComputedStringProperty, hasComputedNumberProperty, propertiesArray, propertiesTable, typeFlags, patternWithComputedProperties, inDestructuringPattern ) as SpreadElementType;
10522
+ const t = createObjectLiteralType() as SpreadElementType;
10514
10523
t.isDeclaredProperty = true;
10515
10524
spreads.push(t);
10516
10525
}
@@ -10520,20 +10529,20 @@ namespace ts {
10520
10529
return spread;
10521
10530
}
10522
10531
10523
- return createObjectLiteralType(node, hasComputedStringProperty, hasComputedNumberProperty, propertiesArray, propertiesTable, typeFlags, patternWithComputedProperties, inDestructuringPattern );
10524
- }
10525
-
10526
- function createObjectLiteralType(node: ObjectLiteralExpression, hasComputedStringProperty: boolean, hasComputedNumberProperty: boolean, propertiesArray: Symbol[], propertiesTable: Map<Symbol>, typeFlags: TypeFlags, patternWithComputedProperties: boolean, inDestructuringPattern: boolean) {
10527
- const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo (node, propertiesArray, IndexKind.String) : undefined ;
10528
- const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined ;
10529
- const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo );
10530
- const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral;
10531
- result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0) ;
10532
- if (inDestructuringPattern) {
10533
- result.pattern = node ;
10532
+ return createObjectLiteralType();
10533
+ function createObjectLiteralType() {
10534
+ const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.String) : undefined;
10535
+ const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined;
10536
+ const result = createAnonymousType (node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo) ;
10537
+ const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral ;
10538
+ result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0 );
10539
+ if (inDestructuringPattern) {
10540
+ result.pattern = node ;
10541
+ }
10542
+ return result ;
10534
10543
}
10535
- return result;
10536
- }
10544
+
10545
+ }
10537
10546
10538
10547
function checkJsxSelfClosingElement(node: JsxSelfClosingElement) {
10539
10548
checkJsxOpeningLikeElement(node);
0 commit comments