@@ -197,6 +197,8 @@ namespace ts {
197
197
const evolvingArrayTypes: EvolvingArrayType[] = [];
198
198
199
199
const unknownSymbol = createSymbol(SymbolFlags.Property, "unknown");
200
+ const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, "<untyped>");
201
+ untypedModuleSymbol.exports = createMap<Symbol>();
200
202
const resolvingSymbol = createSymbol(0, "__resolving__");
201
203
202
204
const anyType = createIntrinsicType(TypeFlags.Any, "any");
@@ -1227,7 +1229,7 @@ namespace ts {
1227
1229
1228
1230
if (moduleSymbol) {
1229
1231
let exportDefaultSymbol: Symbol;
1230
- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1232
+ if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
1231
1233
exportDefaultSymbol = moduleSymbol;
1232
1234
}
1233
1235
else {
@@ -1307,7 +1309,7 @@ namespace ts {
1307
1309
if (targetSymbol) {
1308
1310
const name = specifier.propertyName || specifier.name;
1309
1311
if (name.text) {
1310
- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1312
+ if (isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
1311
1313
return moduleSymbol;
1312
1314
}
1313
1315
@@ -1560,15 +1562,19 @@ namespace ts {
1560
1562
if (isForAugmentation) {
1561
1563
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
1562
1564
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
1565
+ return undefined;
1563
1566
}
1564
1567
else if (compilerOptions.noImplicitAny && moduleNotFoundError) {
1565
1568
error(errorNode,
1566
1569
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
1567
1570
moduleReference,
1568
1571
resolvedModule.resolvedFileName);
1572
+ return undefined;
1569
1573
}
1570
- // Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
1571
- return undefined;
1574
+ // Unlike a failed import, an untyped module produces a dummy symbol.
1575
+ // This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`.
1576
+ // This must be different than `unknownSymbol` because `getBaseConstructorTypeOfClass` won't fail for `unknownSymbol`.
1577
+ return untypedModuleSymbol;
1572
1578
}
1573
1579
1574
1580
if (moduleNotFoundError) {
@@ -3753,7 +3759,7 @@ namespace ts {
3753
3759
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
3754
3760
const links = getSymbolLinks(symbol);
3755
3761
if (!links.type) {
3756
- if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol (symbol)) {
3762
+ if (symbol.flags & SymbolFlags.Module && isUntypedOrShorthandAmbientModuleSymbol (symbol)) {
3757
3763
links.type = anyType;
3758
3764
}
3759
3765
else {
@@ -11578,7 +11584,7 @@ namespace ts {
11578
11584
if (isBindingPattern(declaration.parent)) {
11579
11585
const parentDeclaration = declaration.parent.parent;
11580
11586
const name = declaration.propertyName || declaration.name;
11581
- if (isVariableLike( parentDeclaration) &&
11587
+ if (parentDeclaration.kind !== SyntaxKind.BindingElement &&
11582
11588
parentDeclaration.type &&
11583
11589
!isBindingPattern(name)) {
11584
11590
const text = getTextOfPropertyName(name);
@@ -21138,7 +21144,15 @@ namespace ts {
21138
21144
}
21139
21145
21140
21146
if (isPartOfTypeNode(node)) {
21141
- return getTypeFromTypeNode(<TypeNode>node);
21147
+ let typeFromTypeNode = getTypeFromTypeNode(<TypeNode>node);
21148
+
21149
+ if (typeFromTypeNode && isExpressionWithTypeArgumentsInClassImplementsClause(node)) {
21150
+ const containingClass = getContainingClass(node);
21151
+ const classType = getTypeOfNode(containingClass) as InterfaceType;
21152
+ typeFromTypeNode = getTypeWithThisArgument(typeFromTypeNode, classType.thisType);
21153
+ }
21154
+
21155
+ return typeFromTypeNode;
21142
21156
}
21143
21157
21144
21158
if (isPartOfExpression(node)) {
@@ -21148,7 +21162,10 @@ namespace ts {
21148
21162
if (isExpressionWithTypeArgumentsInClassExtendsClause(node)) {
21149
21163
// A SyntaxKind.ExpressionWithTypeArguments is considered a type node, except when it occurs in the
21150
21164
// extends clause of a class. We handle that case here.
21151
- return getBaseTypes(<InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0];
21165
+ const classNode = getContainingClass(node);
21166
+ const classType = getDeclaredTypeOfSymbol(getSymbolOfNode(classNode)) as InterfaceType;
21167
+ const baseType = getBaseTypes(classType)[0];
21168
+ return baseType && getTypeWithThisArgument(baseType, classType.thisType);
21152
21169
}
21153
21170
21154
21171
if (isTypeDeclaration(node)) {
@@ -21316,7 +21333,7 @@ namespace ts {
21316
21333
21317
21334
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
21318
21335
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
21319
- if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
21336
+ if (!moduleSymbol || isUntypedOrShorthandAmbientModuleSymbol (moduleSymbol)) {
21320
21337
// If the module is not found or is shorthand, assume that it may export a value.
21321
21338
return true;
21322
21339
}
0 commit comments