mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
feat(29624): better errors for non-exported types (#36187)
This commit is contained in:
committed by
Daniel Rosenwasser
parent
342f4c0b54
commit
38eccbab2a
@@ -2355,7 +2355,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (moduleSymbol.exports && moduleSymbol.exports.has(InternalSymbolName.Default)) {
|
||||
if (moduleSymbol.exports?.has(InternalSymbolName.Default)) {
|
||||
error(
|
||||
name,
|
||||
Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead,
|
||||
@@ -2364,7 +2364,7 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
else {
|
||||
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
|
||||
reportNonExportedMember(name, declarationName, moduleSymbol, moduleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2373,6 +2373,27 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function reportNonExportedMember(name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void {
|
||||
const localSymbol = moduleSymbol.valueDeclaration.locals?.get(name.escapedText);
|
||||
const exports = moduleSymbol.exports;
|
||||
|
||||
if (localSymbol) {
|
||||
const exportedSymbol = exports && !exports.has(InternalSymbolName.ExportEquals)
|
||||
? find(symbolsToArray(exports), symbol => !!getSymbolIfSameReference(symbol, localSymbol))
|
||||
: undefined;
|
||||
const diagnostic = exportedSymbol
|
||||
? error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2, moduleName, declarationName, symbolToString(exportedSymbol))
|
||||
: error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName);
|
||||
|
||||
addRelatedInfo(diagnostic,
|
||||
createDiagnosticForNode(localSymbol.valueDeclaration, Diagnostics._0_is_declared_here, declarationName)
|
||||
);
|
||||
}
|
||||
else {
|
||||
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean): Symbol | undefined {
|
||||
const resolved = getExternalModuleMember(node.parent.parent.parent, node, dontResolveAlias);
|
||||
if (resolved && node.parent.parent.isTypeOnly) {
|
||||
|
||||
@@ -1764,6 +1764,14 @@
|
||||
"category": "Error",
|
||||
"code": 2458
|
||||
},
|
||||
"Module '{0}' declares '{1}' locally, but it is not exported.": {
|
||||
"category": "Error",
|
||||
"code": 2459
|
||||
},
|
||||
"Module '{0}' declares '{1}' locally, but it is exported as '{2}'.": {
|
||||
"category": "Error",
|
||||
"code": 2460
|
||||
},
|
||||
"Type '{0}' is not an array type.": {
|
||||
"category": "Error",
|
||||
"code": 2461
|
||||
|
||||
Reference in New Issue
Block a user