@@ -204,8 +204,6 @@ namespace ts {
204
204
const evolvingArrayTypes: EvolvingArrayType[] = [];
205
205
206
206
const unknownSymbol = createSymbol(SymbolFlags.Property, "unknown");
207
- const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, "<untyped>");
208
- untypedModuleSymbol.exports = createMap<Symbol>();
209
207
const resolvingSymbol = createSymbol(0, "__resolving__");
210
208
211
209
const anyType = createIntrinsicType(TypeFlags.Any, "any");
@@ -1267,7 +1265,7 @@ namespace ts {
1267
1265
1268
1266
if (moduleSymbol) {
1269
1267
let exportDefaultSymbol: Symbol;
1270
- if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
1268
+ if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1271
1269
exportDefaultSymbol = moduleSymbol;
1272
1270
}
1273
1271
else {
@@ -1347,7 +1345,7 @@ namespace ts {
1347
1345
if (targetSymbol) {
1348
1346
const name = specifier.propertyName || specifier.name;
1349
1347
if (name.text) {
1350
- if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
1348
+ if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1351
1349
return moduleSymbol;
1352
1350
}
1353
1351
@@ -1623,19 +1621,15 @@ namespace ts {
1623
1621
if (isForAugmentation) {
1624
1622
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
1625
1623
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
1626
- return undefined;
1627
1624
}
1628
1625
else if (noImplicitAny && moduleNotFoundError) {
1629
1626
error(errorNode,
1630
1627
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
1631
1628
moduleReference,
1632
1629
resolvedModule.resolvedFileName);
1633
- return undefined;
1634
1630
}
1635
- // Unlike a failed import, an untyped module produces a dummy symbol.
1636
- // This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`.
1637
- // This must be different than `unknownSymbol` because `getBaseConstructorTypeOfClass` won't fail for `unknownSymbol`.
1638
- return untypedModuleSymbol;
1631
+ // Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
1632
+ return undefined;
1639
1633
}
1640
1634
1641
1635
if (moduleNotFoundError) {
@@ -4405,7 +4399,7 @@ namespace ts {
4405
4399
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
4406
4400
const links = getSymbolLinks(symbol);
4407
4401
if (!links.type) {
4408
- if (symbol.flags & SymbolFlags.Module && isUntypedOrShorthandAmbientModuleSymbol (symbol)) {
4402
+ if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol (symbol)) {
4409
4403
links.type = anyType;
4410
4404
}
4411
4405
else {
@@ -4641,7 +4635,8 @@ namespace ts {
4641
4635
* The base constructor of a class can resolve to
4642
4636
* * undefinedType if the class has no extends clause,
4643
4637
* * unknownType if an error occurred during resolution of the extends expression,
4644
- * * nullType if the extends expression is the null value, or
4638
+ * * nullType if the extends expression is the null value,
4639
+ * * anyType if the extends expression has type any, or
4645
4640
* * an object type with at least one construct signature.
4646
4641
*/
4647
4642
function getBaseConstructorTypeOfClass(type: InterfaceType): Type {
@@ -4663,7 +4658,7 @@ namespace ts {
4663
4658
error(type.symbol.valueDeclaration, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_base_expression, symbolToString(type.symbol));
4664
4659
return type.resolvedBaseConstructorType = unknownType;
4665
4660
}
4666
- if (baseConstructorType !== unknownType && baseConstructorType !== nullWideningType && !isConstructorType(baseConstructorType)) {
4661
+ if (!( baseConstructorType.flags & TypeFlags.Any) && baseConstructorType !== nullWideningType && !isConstructorType(baseConstructorType)) {
4667
4662
error(baseTypeNode.expression, Diagnostics.Type_0_is_not_a_constructor_function_type, typeToString(baseConstructorType));
4668
4663
return type.resolvedBaseConstructorType = unknownType;
4669
4664
}
@@ -4695,7 +4690,7 @@ namespace ts {
4695
4690
function resolveBaseTypesOfClass(type: InterfaceType): void {
4696
4691
type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray;
4697
4692
const baseConstructorType = getApparentType(getBaseConstructorTypeOfClass(type));
4698
- if (!(baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection))) {
4693
+ if (!(baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.Any ))) {
4699
4694
return;
4700
4695
}
4701
4696
const baseTypeNode = getBaseTypeNodeOfClass(type);
@@ -4708,6 +4703,9 @@ namespace ts {
4708
4703
// type arguments in the same manner as a type reference to get the same error reporting experience.
4709
4704
baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseConstructorType.symbol);
4710
4705
}
4706
+ else if (baseConstructorType.flags & TypeFlags.Any) {
4707
+ baseType = baseConstructorType;
4708
+ }
4711
4709
else {
4712
4710
// The class derives from a "class-like" constructor function, check that we have at least one construct signature
4713
4711
// with a matching number of type parameters and use the return type of the first instantiated signature. Elsewhere
@@ -4761,10 +4759,10 @@ namespace ts {
4761
4759
return true;
4762
4760
}
4763
4761
4764
- // A valid base type is any non-generic object type or intersection of non-generic
4762
+ // A valid base type is `any`, any non-generic object type or intersection of non-generic
4765
4763
// object types.
4766
4764
function isValidBaseType(type: Type): boolean {
4767
- return type.flags & (TypeFlags.Object | TypeFlags.NonPrimitive) && !isGenericMappedType(type) ||
4765
+ return type.flags & (TypeFlags.Object | TypeFlags.NonPrimitive | TypeFlags.Any ) && !isGenericMappedType(type) ||
4768
4766
type.flags & TypeFlags.Intersection && !forEach((<IntersectionType>type).types, t => !isValidBaseType(t));
4769
4767
}
4770
4768
@@ -5176,7 +5174,11 @@ namespace ts {
5176
5174
addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType));
5177
5175
callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call));
5178
5176
constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct));
5179
- stringIndexInfo = stringIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.String);
5177
+ if (!stringIndexInfo) {
5178
+ stringIndexInfo = instantiatedBaseType === anyType ?
5179
+ createIndexInfo(anyType, /*isReadonly*/ false) :
5180
+ getIndexInfoOfType(instantiatedBaseType, IndexKind.String);
5181
+ }
5180
5182
numberIndexInfo = numberIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.Number);
5181
5183
}
5182
5184
}
@@ -5418,6 +5420,7 @@ namespace ts {
5418
5420
// Combinations of function, class, enum and module
5419
5421
let members = emptySymbols;
5420
5422
let constructSignatures: Signature[] = emptyArray;
5423
+ let stringIndexInfo: IndexInfo = undefined;
5421
5424
if (symbol.exports) {
5422
5425
members = getExportsOfSymbol(symbol);
5423
5426
}
@@ -5432,9 +5435,12 @@ namespace ts {
5432
5435
members = createSymbolTable(getNamedMembers(members));
5433
5436
addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
5434
5437
}
5438
+ else if (baseConstructorType === anyType) {
5439
+ stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
5440
+ }
5435
5441
}
5436
5442
const numberIndexInfo = symbol.flags & SymbolFlags.Enum ? enumNumberIndexInfo : undefined;
5437
- setStructuredTypeMembers(type, members, emptyArray, constructSignatures, undefined , numberIndexInfo);
5443
+ setStructuredTypeMembers(type, members, emptyArray, constructSignatures, stringIndexInfo , numberIndexInfo);
5438
5444
// We resolve the members before computing the signatures because a signature may use
5439
5445
// typeof with a qualified name expression that circularly references the type we are
5440
5446
// in the process of resolving (see issue #6072). The temporarily empty signature list
@@ -22172,7 +22178,7 @@ namespace ts {
22172
22178
22173
22179
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
22174
22180
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
22175
- if (!moduleSymbol || isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
22181
+ if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
22176
22182
// If the module is not found or is shorthand, assume that it may export a value.
22177
22183
return true;
22178
22184
}
0 commit comments