Provide a more helpful error message when incorrectly using qualified names in the case of 'Type.propertyName'.

This commit is contained in:
Daniel Rosenwasser 2017-07-27 11:44:26 -07:00
parent 677cc66e03
commit 497e3cfb68
2 changed files with 18 additions and 0 deletions

View file

@ -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;
}

View file

@ -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",