@@ -95,6 +95,7 @@ namespace ts {
95
95
getTypeAtLocation: getTypeOfNode,
96
96
getPropertySymbolOfDestructuringAssignment,
97
97
signatureToString,
98
+ indexSignatureToString,
98
99
typeToString,
99
100
getSymbolDisplayBuilder,
100
101
symbolToString,
@@ -2035,6 +2036,15 @@ namespace ts {
2035
2036
return result;
2036
2037
}
2037
2038
2039
+ function indexSignatureToString(info: IndexInfo, kind: SyntaxKind, enclosingDeclaration?: Node): string {
2040
+ const writer = getSingleLineStringWriter();
2041
+ getSymbolDisplayBuilder().buildIndexSignatureDisplay(info, writer, kind, enclosingDeclaration);
2042
+ const result = writer.string();
2043
+ releaseStringWriter(writer);
2044
+
2045
+ return result;
2046
+ }
2047
+
2038
2048
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
2039
2049
const writer = getSingleLineStringWriter();
2040
2050
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
@@ -2459,26 +2469,6 @@ namespace ts {
2459
2469
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags);
2460
2470
}
2461
2471
2462
- function writeIndexSignature(info: IndexInfo, keyword: SyntaxKind) {
2463
- if (info) {
2464
- if (info.isReadonly) {
2465
- writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
2466
- writeSpace(writer);
2467
- }
2468
- writePunctuation(writer, SyntaxKind.OpenBracketToken);
2469
- writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x");
2470
- writePunctuation(writer, SyntaxKind.ColonToken);
2471
- writeSpace(writer);
2472
- writeKeyword(writer, keyword);
2473
- writePunctuation(writer, SyntaxKind.CloseBracketToken);
2474
- writePunctuation(writer, SyntaxKind.ColonToken);
2475
- writeSpace(writer);
2476
- writeType(info.type, TypeFormatFlags.None);
2477
- writePunctuation(writer, SyntaxKind.SemicolonToken);
2478
- writer.writeLine();
2479
- }
2480
- }
2481
-
2482
2472
function writePropertyWithModifiers(prop: Symbol) {
2483
2473
if (isReadonlySymbol(prop)) {
2484
2474
writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
@@ -2566,8 +2556,8 @@ namespace ts {
2566
2556
writePunctuation(writer, SyntaxKind.SemicolonToken);
2567
2557
writer.writeLine();
2568
2558
}
2569
- writeIndexSignature (resolved.stringIndexInfo, SyntaxKind.StringKeyword);
2570
- writeIndexSignature (resolved.numberIndexInfo, SyntaxKind.NumberKeyword);
2559
+ buildIndexSignatureDisplay (resolved.stringIndexInfo, writer, SyntaxKind.StringKeyword, enclosingDeclaration, globalFlags, symbolStack );
2560
+ buildIndexSignatureDisplay (resolved.numberIndexInfo, writer, SyntaxKind.NumberKeyword, enclosingDeclaration, globalFlags, symbolStack );
2571
2561
for (const p of resolved.properties) {
2572
2562
const t = getTypeOfSymbol(p);
2573
2563
if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) {
@@ -2800,6 +2790,29 @@ namespace ts {
2800
2790
buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
2801
2791
}
2802
2792
2793
+ /**
2794
+ * @param keyword The keyword for the type of IndexSignature. Must be one of SyntaxKind.NumberKeyword or SyntaxKind.StringKeyword.
2795
+ */
2796
+ function buildIndexSignatureDisplay(info: IndexInfo, writer: SymbolWriter, keyword: SyntaxKind, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2797
+ if (info) {
2798
+ if (info.isReadonly) {
2799
+ writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
2800
+ writeSpace(writer);
2801
+ }
2802
+ writePunctuation(writer, SyntaxKind.OpenBracketToken);
2803
+ writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x");
2804
+ writePunctuation(writer, SyntaxKind.ColonToken);
2805
+ writeSpace(writer);
2806
+ writeKeyword(writer, keyword);
2807
+ writePunctuation(writer, SyntaxKind.CloseBracketToken);
2808
+ writePunctuation(writer, SyntaxKind.ColonToken);
2809
+ writeSpace(writer);
2810
+ buildTypeDisplay(info.type, writer, enclosingDeclaration, globalFlags, symbolStack);
2811
+ writePunctuation(writer, SyntaxKind.SemicolonToken);
2812
+ writer.writeLine();
2813
+ }
2814
+ }
2815
+
2803
2816
return _displayBuilder || (_displayBuilder = {
2804
2817
buildSymbolDisplay,
2805
2818
buildTypeDisplay,
@@ -2810,6 +2823,7 @@ namespace ts {
2810
2823
buildDisplayForTypeParametersAndDelimiters,
2811
2824
buildTypeParameterDisplayFromSymbol,
2812
2825
buildSignatureDisplay,
2826
+ buildIndexSignatureDisplay,
2813
2827
buildReturnTypeDisplay
2814
2828
});
2815
2829
}
0 commit comments