@@ -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,
@@ -114,7 +117,8 @@ namespace ts {
114
117
// we deliberately exclude augmentations
115
118
// since we are only interested in declarations of the module itself
116
119
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
117
- }
120
+ },
121
+ getApparentType
118
122
};
119
123
120
124
const tupleTypes: GenericType[] = [];
@@ -1368,7 +1372,9 @@ namespace ts {
1368
1372
return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
1369
1373
}
1370
1374
1371
- // Resolves a qualified name and any involved aliases
1375
+ /**
1376
+ * Resolves a qualified name and any involved aliases.
1377
+ */
1372
1378
function resolveEntityName(name: EntityNameOrEntityNameExpression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean, location?: Node): Symbol | undefined {
1373
1379
if (nodeIsMissing(name)) {
1374
1380
return undefined;
@@ -2109,7 +2115,7 @@ namespace ts {
2109
2115
return result || types;
2110
2116
}
2111
2117
2112
- function visibilityToString(flags: ModifierFlags) {
2118
+ function visibilityToString(flags: ModifierFlags): string | undefined {
2113
2119
if (flags === ModifierFlags.Private) {
2114
2120
return "private";
2115
2121
}
@@ -2488,26 +2494,6 @@ namespace ts {
2488
2494
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags);
2489
2495
}
2490
2496
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
2497
function writePropertyWithModifiers(prop: Symbol) {
2512
2498
if (isReadonlySymbol(prop)) {
2513
2499
writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
@@ -2595,8 +2581,8 @@ namespace ts {
2595
2581
writePunctuation(writer, SyntaxKind.SemicolonToken);
2596
2582
writer.writeLine();
2597
2583
}
2598
- writeIndexSignature (resolved.stringIndexInfo, SyntaxKind.StringKeyword );
2599
- writeIndexSignature (resolved.numberIndexInfo, SyntaxKind.NumberKeyword );
2584
+ buildIndexSignatureDisplay (resolved.stringIndexInfo, writer, IndexKind.String, enclosingDeclaration, globalFlags, symbolStack );
2585
+ buildIndexSignatureDisplay (resolved.numberIndexInfo, writer, IndexKind.Number, enclosingDeclaration, globalFlags, symbolStack );
2600
2586
for (const p of resolved.properties) {
2601
2587
const t = getTypeOfSymbol(p);
2602
2588
if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) {
@@ -2787,6 +2773,11 @@ namespace ts {
2787
2773
}
2788
2774
2789
2775
function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2776
+ const returnType = getReturnTypeOfSignature(signature);
2777
+ if (flags & TypeFormatFlags.SuppressAnyReturnType && isTypeAny(returnType)) {
2778
+ return;
2779
+ }
2780
+
2790
2781
if (flags & TypeFormatFlags.WriteArrowStyleSignature) {
2791
2782
writeSpace(writer);
2792
2783
writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken);
@@ -2800,7 +2791,6 @@ namespace ts {
2800
2791
buildTypePredicateDisplay(signature.typePredicate, writer, enclosingDeclaration, flags, symbolStack);
2801
2792
}
2802
2793
else {
2803
- const returnType = getReturnTypeOfSignature(signature);
2804
2794
buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack);
2805
2795
}
2806
2796
}
@@ -2825,6 +2815,34 @@ namespace ts {
2825
2815
buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
2826
2816
}
2827
2817
2818
+ function buildIndexSignatureDisplay(info: IndexInfo, writer: SymbolWriter, kind: IndexKind, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2819
+ if (info) {
2820
+ if (info.isReadonly) {
2821
+ writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
2822
+ writeSpace(writer);
2823
+ }
2824
+ writePunctuation(writer, SyntaxKind.OpenBracketToken);
2825
+ writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x");
2826
+ writePunctuation(writer, SyntaxKind.ColonToken);
2827
+ writeSpace(writer);
2828
+ switch (kind) {
2829
+ case IndexKind.Number:
2830
+ writeKeyword(writer, SyntaxKind.NumberKeyword);
2831
+ break;
2832
+ case IndexKind.String:
2833
+ writeKeyword(writer, SyntaxKind.StringKeyword);
2834
+ break;
2835
+ }
2836
+
2837
+ writePunctuation(writer, SyntaxKind.CloseBracketToken);
2838
+ writePunctuation(writer, SyntaxKind.ColonToken);
2839
+ writeSpace(writer);
2840
+ buildTypeDisplay(info.type, writer, enclosingDeclaration, globalFlags, symbolStack);
2841
+ writePunctuation(writer, SyntaxKind.SemicolonToken);
2842
+ writer.writeLine();
2843
+ }
2844
+ }
2845
+
2828
2846
return _displayBuilder || (_displayBuilder = {
2829
2847
buildSymbolDisplay,
2830
2848
buildTypeDisplay,
@@ -2835,6 +2853,7 @@ namespace ts {
2835
2853
buildDisplayForTypeParametersAndDelimiters,
2836
2854
buildTypeParameterDisplayFromSymbol,
2837
2855
buildSignatureDisplay,
2856
+ buildIndexSignatureDisplay,
2838
2857
buildReturnTypeDisplay
2839
2858
});
2840
2859
}
@@ -3786,11 +3805,13 @@ namespace ts {
3786
3805
return signatures;
3787
3806
}
3788
3807
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.
3808
+ /**
3809
+ * The base constructor of a class can resolve to
3810
+ * * undefinedType if the class has no extends clause,
3811
+ * * unknownType if an error occurred during resolution of the extends expression,
3812
+ * * nullType if the extends expression is the null value, or
3813
+ * * an object type with at least one construct signature.
3814
+ */
3794
3815
function getBaseConstructorTypeOfClass(type: InterfaceType): Type {
3795
3816
if (!type.resolvedBaseConstructorType) {
3796
3817
const baseTypeNode = getBaseTypeNodeOfClass(type);
@@ -4271,7 +4292,7 @@ namespace ts {
4271
4292
return <InterfaceTypeWithDeclaredMembers>type;
4272
4293
}
4273
4294
4274
- function getTypeWithThisArgument(type: Type, thisArgument?: Type) {
4295
+ function getTypeWithThisArgument(type: Type, thisArgument?: Type): Type {
4275
4296
if (getObjectFlags(type) & ObjectFlags.Reference) {
4276
4297
return createTypeReference((<TypeReference>type).target,
4277
4298
concatenate((<TypeReference>type).typeArguments, [thisArgument || (<TypeReference>type).target.thisType]));
@@ -4497,6 +4518,9 @@ namespace ts {
4497
4518
setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
4498
4519
}
4499
4520
4521
+ /**
4522
+ * Converts an AnonymousType to a ResolvedType.
4523
+ */
4500
4524
function resolveAnonymousTypeMembers(type: AnonymousType) {
4501
4525
const symbol = type.symbol;
4502
4526
if (type.target) {
@@ -6629,17 +6653,19 @@ namespace ts {
6629
6653
const constraintType = getConstraintTypeFromMappedType(type);
6630
6654
if (constraintType.flags & TypeFlags.Index) {
6631
6655
const typeVariable = (<IndexType>constraintType).type;
6632
- const mappedTypeVariable = instantiateType(typeVariable, mapper);
6633
- if (typeVariable !== mappedTypeVariable) {
6634
- return mapType(mappedTypeVariable, t => {
6635
- if (isMappableType(t)) {
6636
- const replacementMapper = createUnaryTypeMapper(typeVariable, t);
6637
- const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper);
6638
- combinedMapper.mappedTypes = mapper.mappedTypes;
6639
- return instantiateMappedObjectType(type, combinedMapper);
6640
- }
6641
- return t;
6642
- });
6656
+ if (typeVariable.flags & TypeFlags.TypeParameter) {
6657
+ const mappedTypeVariable = instantiateType(typeVariable, mapper);
6658
+ if (typeVariable !== mappedTypeVariable) {
6659
+ return mapType(mappedTypeVariable, t => {
6660
+ if (isMappableType(t)) {
6661
+ const replacementMapper = createUnaryTypeMapper(typeVariable, t);
6662
+ const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper);
6663
+ combinedMapper.mappedTypes = mapper.mappedTypes;
6664
+ return instantiateMappedObjectType(type, combinedMapper);
6665
+ }
6666
+ return t;
6667
+ });
6668
+ }
6643
6669
}
6644
6670
}
6645
6671
return instantiateMappedObjectType(type, mapper);
@@ -7278,10 +7304,12 @@ namespace ts {
7278
7304
return false;
7279
7305
}
7280
7306
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.
7307
+ /**
7308
+ * Compare two types and return
7309
+ * * Ternary.True if they are related with no assumptions,
7310
+ * * Ternary.Maybe if they are related with assumptions of other relationships, or
7311
+ * * Ternary.False if they are not related.
7312
+ */
7285
7313
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
7286
7314
let result: Ternary;
7287
7315
if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {
0 commit comments