mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Give good error messages on more types.
This commit is contained in:
parent
341f9cf1d6
commit
3382a2ea54
@ -1716,7 +1716,7 @@ namespace ts {
|
||||
}
|
||||
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
|
||||
if (symbol && !(symbol.flags & SymbolFlags.NamespaceModule)) {
|
||||
const message = (name === "Promise" || name === "Symbol")
|
||||
const message = isES2015OrLaterConstructorName(name)
|
||||
? Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later
|
||||
: Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here;
|
||||
error(errorLocation, message, unescapeLeadingUnderscores(name));
|
||||
@ -1726,6 +1726,19 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isES2015OrLaterConstructorName(n: __String) {
|
||||
switch (n) {
|
||||
case "Promise":
|
||||
case "Symbol":
|
||||
case "Map":
|
||||
case "WeakMap":
|
||||
case "Set":
|
||||
case "WeakSet":
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
|
||||
if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule & ~SymbolFlags.Type)) {
|
||||
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.NamespaceModule & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user