@@ -79,9 +79,11 @@ namespace ts {
79
79
getDeclaredTypeOfSymbol,
80
80
getPropertiesOfType,
81
81
getPropertyOfType,
82
+ getIndexInfoOfType,
82
83
getSignaturesOfType,
83
84
getIndexTypeOfType,
84
85
getBaseTypes,
86
+ getTypeFromTypeNode,
85
87
getReturnTypeOfSignature,
86
88
getNonNullableType,
87
89
getSymbolsInScope,
@@ -90,6 +92,7 @@ namespace ts {
90
92
getExportSpecifierLocalTargetSymbol,
91
93
getTypeAtLocation: getTypeOfNode,
92
94
getPropertySymbolOfDestructuringAssignment,
95
+ signatureToString,
93
96
typeToString,
94
97
getSymbolDisplayBuilder,
95
98
symbolToString,
@@ -1369,7 +1372,9 @@ namespace ts {
1369
1372
return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
1370
1373
}
1371
1374
1372
- // Resolves a qualified name and any involved aliases
1375
+ /**
1376
+ * Resolves a qualified name and any involved aliases.
1377
+ */
1373
1378
function resolveEntityName(name: EntityNameOrEntityNameExpression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean, location?: Node): Symbol | undefined {
1374
1379
if (nodeIsMissing(name)) {
1375
1380
return undefined;
@@ -2110,7 +2115,7 @@ namespace ts {
2110
2115
return result || types;
2111
2116
}
2112
2117
2113
- function visibilityToString(flags: ModifierFlags) {
2118
+ function visibilityToString(flags: ModifierFlags): string | undefined {
2114
2119
if (flags === ModifierFlags.Private) {
2115
2120
return "private";
2116
2121
}
@@ -2488,26 +2493,6 @@ namespace ts {
2488
2493
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags);
2489
2494
}
2490
2495
2491
- function writeIndexSignature(info: IndexInfo, keyword: SyntaxKind) {
2492
- if (info) {
2493
- if (info.isReadonly) {
2494
- writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
2495
- writeSpace(writer);
2496
- }
2497
- writePunctuation(writer, SyntaxKind.OpenBracketToken);
2498
- writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x");
2499
- writePunctuation(writer, SyntaxKind.ColonToken);
2500
- writeSpace(writer);
2501
- writeKeyword(writer, keyword);
2502
- writePunctuation(writer, SyntaxKind.CloseBracketToken);
2503
- writePunctuation(writer, SyntaxKind.ColonToken);
2504
- writeSpace(writer);
2505
- writeType(info.type, TypeFormatFlags.None);
2506
- writePunctuation(writer, SyntaxKind.SemicolonToken);
2507
- writer.writeLine();
2508
- }
2509
- }
2510
-
2511
2496
function writePropertyWithModifiers(prop: Symbol) {
2512
2497
if (isReadonlySymbol(prop)) {
2513
2498
writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
@@ -2595,8 +2580,8 @@ namespace ts {
2595
2580
writePunctuation(writer, SyntaxKind.SemicolonToken);
2596
2581
writer.writeLine();
2597
2582
}
2598
- writeIndexSignature (resolved.stringIndexInfo, SyntaxKind.StringKeyword );
2599
- writeIndexSignature (resolved.numberIndexInfo, SyntaxKind.NumberKeyword );
2583
+ buildIndexSignatureDisplay (resolved.stringIndexInfo, writer, IndexKind.String, enclosingDeclaration, globalFlags, symbolStack );
2584
+ buildIndexSignatureDisplay (resolved.numberIndexInfo, writer, IndexKind.Number, enclosingDeclaration, globalFlags, symbolStack );
2600
2585
for (const p of resolved.properties) {
2601
2586
const t = getTypeOfSymbol(p);
2602
2587
if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) {
@@ -2787,6 +2772,11 @@ namespace ts {
2787
2772
}
2788
2773
2789
2774
function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2775
+ const returnType = getReturnTypeOfSignature(signature);
2776
+ if (flags & TypeFormatFlags.SuppressAnyReturnType && isTypeAny(returnType)) {
2777
+ return;
2778
+ }
2779
+
2790
2780
if (flags & TypeFormatFlags.WriteArrowStyleSignature) {
2791
2781
writeSpace(writer);
2792
2782
writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken);
@@ -2800,7 +2790,6 @@ namespace ts {
2800
2790
buildTypePredicateDisplay(signature.typePredicate, writer, enclosingDeclaration, flags, symbolStack);
2801
2791
}
2802
2792
else {
2803
- const returnType = getReturnTypeOfSignature(signature);
2804
2793
buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack);
2805
2794
}
2806
2795
}
@@ -2825,6 +2814,34 @@ namespace ts {
2825
2814
buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
2826
2815
}
2827
2816
2817
+ function buildIndexSignatureDisplay(info: IndexInfo, writer: SymbolWriter, kind: IndexKind, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2818
+ if (info) {
2819
+ if (info.isReadonly) {
2820
+ writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
2821
+ writeSpace(writer);
2822
+ }
2823
+ writePunctuation(writer, SyntaxKind.OpenBracketToken);
2824
+ writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x");
2825
+ writePunctuation(writer, SyntaxKind.ColonToken);
2826
+ writeSpace(writer);
2827
+ switch (kind) {
2828
+ case IndexKind.Number:
2829
+ writeKeyword(writer, SyntaxKind.NumberKeyword);
2830
+ break;
2831
+ case IndexKind.String:
2832
+ writeKeyword(writer, SyntaxKind.StringKeyword);
2833
+ break;
2834
+ }
2835
+
2836
+ writePunctuation(writer, SyntaxKind.CloseBracketToken);
2837
+ writePunctuation(writer, SyntaxKind.ColonToken);
2838
+ writeSpace(writer);
2839
+ buildTypeDisplay(info.type, writer, enclosingDeclaration, globalFlags, symbolStack);
2840
+ writePunctuation(writer, SyntaxKind.SemicolonToken);
2841
+ writer.writeLine();
2842
+ }
2843
+ }
2844
+
2828
2845
return _displayBuilder || (_displayBuilder = {
2829
2846
buildSymbolDisplay,
2830
2847
buildTypeDisplay,
@@ -2835,6 +2852,7 @@ namespace ts {
2835
2852
buildDisplayForTypeParametersAndDelimiters,
2836
2853
buildTypeParameterDisplayFromSymbol,
2837
2854
buildSignatureDisplay,
2855
+ buildIndexSignatureDisplay,
2838
2856
buildReturnTypeDisplay
2839
2857
});
2840
2858
}
@@ -3786,11 +3804,13 @@ namespace ts {
3786
3804
return signatures;
3787
3805
}
3788
3806
3789
- // The base constructor of a class can resolve to
3790
- // undefinedType if the class has no extends clause,
3791
- // unknownType if an error occurred during resolution of the extends expression,
3792
- // nullType if the extends expression is the null value, or
3793
- // an object type with at least one construct signature.
3807
+ /**
3808
+ * The base constructor of a class can resolve to
3809
+ * * undefinedType if the class has no extends clause,
3810
+ * * unknownType if an error occurred during resolution of the extends expression,
3811
+ * * nullType if the extends expression is the null value, or
3812
+ * * an object type with at least one construct signature.
3813
+ */
3794
3814
function getBaseConstructorTypeOfClass(type: InterfaceType): Type {
3795
3815
if (!type.resolvedBaseConstructorType) {
3796
3816
const baseTypeNode = getBaseTypeNodeOfClass(type);
@@ -4271,7 +4291,7 @@ namespace ts {
4271
4291
return <InterfaceTypeWithDeclaredMembers>type;
4272
4292
}
4273
4293
4274
- function getTypeWithThisArgument(type: Type, thisArgument?: Type) {
4294
+ function getTypeWithThisArgument(type: Type, thisArgument?: Type): Type {
4275
4295
if (getObjectFlags(type) & ObjectFlags.Reference) {
4276
4296
return createTypeReference((<TypeReference>type).target,
4277
4297
concatenate((<TypeReference>type).typeArguments, [thisArgument || (<TypeReference>type).target.thisType]));
@@ -4497,6 +4517,9 @@ namespace ts {
4497
4517
setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
4498
4518
}
4499
4519
4520
+ /**
4521
+ * Converts an AnonymousType to a ResolvedType.
4522
+ */
4500
4523
function resolveAnonymousTypeMembers(type: AnonymousType) {
4501
4524
const symbol = type.symbol;
4502
4525
if (type.target) {
@@ -7278,10 +7301,12 @@ namespace ts {
7278
7301
return false;
7279
7302
}
7280
7303
7281
- // Compare two types and return
7282
- // Ternary.True if they are related with no assumptions,
7283
- // Ternary.Maybe if they are related with assumptions of other relationships, or
7284
- // Ternary.False if they are not related.
7304
+ /**
7305
+ * Compare two types and return
7306
+ * * Ternary.True if they are related with no assumptions,
7307
+ * * Ternary.Maybe if they are related with assumptions of other relationships, or
7308
+ * * Ternary.False if they are not related.
7309
+ */
7285
7310
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
7286
7311
let result: Ternary;
7287
7312
if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {
0 commit comments