diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fa2a56e2fdfa6..8f420077f27ac 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3869,7 +3869,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return exportDefaultSymbol; } const hasDefaultOnly = isOnlyImportableAsDefault(specifier, moduleSymbol); - const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + let hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + // For export specifiers re-exporting 'default' from declaration files, when allowSyntheticDefaultImports + // is enabled, allow synthetic default. Declaration files may correspond to CommonJS modules at runtime, + // where a default import is allowed to reference the whole module.exports symbol. + if (!hasSyntheticDefault && isExportSpecifier(node) && allowSyntheticDefaultImports && (!file || file.isDeclarationFile)) { + hasSyntheticDefault = true; + } if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { if (hasExportAssignmentSymbol(moduleSymbol) && !allowSyntheticDefaultImports) { const compilerOptionName = moduleKind >= ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";