mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Improve error message for using value as type.
This commit is contained in:
parent
6d2b738bd8
commit
950861ec7f
@ -1518,7 +1518,8 @@ namespace ts {
|
||||
!checkAndReportErrorForExtendingInterface(errorLocation) &&
|
||||
!checkAndReportErrorForUsingTypeAsNamespace(errorLocation, name, meaning) &&
|
||||
!checkAndReportErrorForUsingTypeAsValue(errorLocation, name, meaning) &&
|
||||
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning)) {
|
||||
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
|
||||
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
|
||||
let suggestion: Symbol | undefined;
|
||||
if (suggestedNameNotFoundMessage && suggestionCount < maximumSuggestionCount) {
|
||||
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
|
||||
@ -1708,6 +1709,17 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkAndReportErrorForUsingValueAsType(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
|
||||
if (meaning & (SymbolFlags.Type & ~SymbolFlags.Namespace)) {
|
||||
const symbol = resolveSymbol(resolveName(errorLocation, name, ~SymbolFlags.Type & SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
|
||||
if (symbol && !(symbol.flags & SymbolFlags.Namespace)) {
|
||||
error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here, unescapeLeadingUnderscores(name));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
|
||||
if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) {
|
||||
if (name === "any" || name === "string" || name === "number" || name === "boolean" || name === "never") {
|
||||
|
||||
@ -2581,6 +2581,10 @@
|
||||
"category": "Error",
|
||||
"code": 2748
|
||||
},
|
||||
"'{0}' refers to a value, but is being used as a type here.": {
|
||||
"category": "Error",
|
||||
"code": 2749
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user