Provide a more helpful error message when incorrectly using qualified names in the case of 'Type.propertyName'.
This commit is contained in:
parent
677cc66e03
commit
497e3cfb68
|
@ -1240,7 +1240,21 @@ namespace ts {
|
|||
function checkAndReportErrorForUsingTypeAsNamespace(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean {
|
||||
if (meaning === SymbolFlags.Namespace) {
|
||||
const symbol = resolveSymbol(resolveName(errorLocation, name, SymbolFlags.Type & ~SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined));
|
||||
const parent = errorLocation.parent;
|
||||
if (symbol) {
|
||||
if (isQualifiedName(parent)) {
|
||||
const propName = parent.right.escapedText;
|
||||
const propType = getPropertyOfType(getDeclaredTypeOfSymbol(symbol), propName);
|
||||
if (propType) {
|
||||
error(
|
||||
parent,
|
||||
Diagnostics.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1,
|
||||
unescapeLeadingUnderscores(name),
|
||||
unescapeLeadingUnderscores(propName),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
error(errorLocation, Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_namespace_here, unescapeLeadingUnderscores(name));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2192,6 +2192,10 @@
|
|||
"category": "Error",
|
||||
"code": 2712
|
||||
},
|
||||
"Cannot access '{0}.{1}' because '{0}' is a type, but not a namespace. Did you mean to retrieve the type of the property '{1}' in '{0}' with '{0}[\"{1}\"]'?": {
|
||||
"category": "Error",
|
||||
"code": 2713
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
|
Loading…
Reference in a new issue