@@ -1069,7 +1069,7 @@ namespace ts {
10691069 const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
10701070
10711071 if (moduleSymbol) {
1072- const exportDefaultSymbol = isShorthandAmbientModuleSymbol (moduleSymbol) ?
1072+ const exportDefaultSymbol = isUntypedModuleSymbol (moduleSymbol) ?
10731073 moduleSymbol :
10741074 moduleSymbol.exports["export="] ?
10751075 getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
@@ -1145,7 +1145,7 @@ namespace ts {
11451145 if (targetSymbol) {
11461146 const name = specifier.propertyName || specifier.name;
11471147 if (name.text) {
1148- if (isShorthandAmbientModuleSymbol (moduleSymbol)) {
1148+ if (isUntypedModuleSymbol (moduleSymbol)) {
11491149 return moduleSymbol;
11501150 }
11511151
@@ -1365,8 +1365,9 @@ namespace ts {
13651365 }
13661366
13671367 const isRelative = isExternalModuleNameRelative(moduleName);
1368+ const quotedName = '"' + moduleName + '"';
13681369 if (!isRelative) {
1369- const symbol = getSymbol(globals, '"' + moduleName + '"' , SymbolFlags.ValueModule);
1370+ const symbol = getSymbol(globals, quotedName , SymbolFlags.ValueModule);
13701371 if (symbol) {
13711372 // merged symbol is module declaration symbol combined with all augmentations
13721373 return getMergedSymbol(symbol);
@@ -1395,6 +1396,28 @@ namespace ts {
13951396 }
13961397 }
13971398
1399+ // May be an untyped module. If so, ignore resolutionDiagnostic.
1400+ if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) {.
1401+ if (compilerOptions.noImplicitAny) {
1402+ if (moduleNotFoundError) {
1403+ error(errorNode,
1404+ Diagnostics.A_package_for_0_was_found_at_1_but_is_untyped_Because_noImplicitAny_is_enabled_this_package_must_have_a_declaration,
1405+ moduleReference,
1406+ resolvedModule.resolvedFileName);
1407+ }
1408+ return undefined;
1409+ }
1410+
1411+ // Create a new symbol to represent the untyped module and store it in globals.
1412+ // This provides a name to the module. See the test tests/cases/fourslash/untypedModuleImport.ts
1413+ const newSymbol = createSymbol(SymbolFlags.ValueModule, quotedName);
1414+ // Module symbols are expected to have 'exports', although since this is an untyped module it can be empty.
1415+ newSymbol.exports = createMap<Symbol>();
1416+ // Cache it so subsequent accesses will return the same module.
1417+ globals[quotedName] = newSymbol;
1418+ return newSymbol;
1419+ }
1420+
13981421 if (moduleNotFoundError) {
13991422 // report errors only if it was requested
14001423 if (resolutionDiagnostic) {
@@ -3462,7 +3485,7 @@ namespace ts {
34623485 function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
34633486 const links = getSymbolLinks(symbol);
34643487 if (!links.type) {
3465- if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol (symbol)) {
3488+ if (symbol.flags & SymbolFlags.Module && isUntypedModuleSymbol (symbol)) {
34663489 links.type = anyType;
34673490 }
34683491 else {
@@ -19011,7 +19034,7 @@ namespace ts {
1901119034
1901219035 function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
1901319036 let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
19014- if (!moduleSymbol || isShorthandAmbientModuleSymbol (moduleSymbol)) {
19037+ if (!moduleSymbol || isUntypedModuleSymbol (moduleSymbol)) {
1901519038 // If the module is not found or is shorthand, assume that it may export a value.
1901619039 return true;
1901719040 }
@@ -19512,7 +19535,7 @@ namespace ts {
1951219535 (typeReferenceDirectives || (typeReferenceDirectives = [])).push(typeReferenceDirective);
1951319536 }
1951419537 else {
19515- // found at least one entry that does not originate from type reference directive
19538+ // found at least one entry that does not originate from type reference directive
1951619539 return undefined;
1951719540 }
1951819541 }
0 commit comments