mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Bad error message when default 'import'-ing an 'export =' without 'esModuleInterop'
This commit is contained in:
@@ -1953,7 +1953,21 @@ namespace ts {
|
||||
const file = find(moduleSymbol.declarations, isSourceFile);
|
||||
const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias);
|
||||
if (!exportDefaultSymbol && !hasSyntheticDefault) {
|
||||
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
|
||||
if (hasExportAssignmentSymbol(moduleSymbol)) {
|
||||
const compilerOptionName = moduleKind >= ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";
|
||||
const exportEqualsSymbol = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals);
|
||||
const exportAssignment = exportEqualsSymbol!.valueDeclaration;
|
||||
const err = error(node.name, Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName);
|
||||
|
||||
addRelatedInfo(err, createDiagnosticForNode(
|
||||
exportAssignment,
|
||||
Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag,
|
||||
compilerOptionName
|
||||
));
|
||||
}
|
||||
else {
|
||||
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
|
||||
}
|
||||
}
|
||||
else if (hasSyntheticDefault) {
|
||||
// per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present
|
||||
|
||||
@@ -851,6 +851,10 @@
|
||||
"category": "Error",
|
||||
"code": 1258
|
||||
},
|
||||
"Module '{0}' can only be default-imported using the '{1}' flag": {
|
||||
"category": "Error",
|
||||
"code": 1259
|
||||
},
|
||||
"'with' statements are not allowed in an async function block.": {
|
||||
"category": "Error",
|
||||
"code": 1300
|
||||
@@ -2156,6 +2160,10 @@
|
||||
"category": "Error",
|
||||
"code": 2593
|
||||
},
|
||||
"This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag.": {
|
||||
"category": "Error",
|
||||
"code": 2594
|
||||
},
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
|
||||
Reference in New Issue
Block a user