@@ -3322,7 +3322,6 @@ namespace ts {
33223322 // Anonymous types without a symbol are never circular.
33233323 return createTypeNodeFromObjectType(type);
33243324 }
3325-
33263325 function shouldWriteTypeOfFunctionSymbol() {
33273326 const isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method) && // typeof static method
33283327 some(symbol.declarations, declaration => hasModifier(declaration, ModifierFlags.Static));
@@ -9158,7 +9157,10 @@ namespace ts {
91589157 }
91599158 if (accessExpression && !isConstEnumObjectType(objectType)) {
91609159 if (noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) {
9161- if (getIndexTypeOfType(objectType, IndexKind.Number)) {
9160+ if (propName !== undefined && typeHasStaticProperty(propName, objectType)) {
9161+ error(accessExpression, Diagnostics.Property_0_is_a_static_member_of_type_1, propName as string, typeToString(objectType));
9162+ }
9163+ else if (getIndexTypeOfType(objectType, IndexKind.Number)) {
91629164 error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number);
91639165 }
91649166 else {
@@ -18055,29 +18057,38 @@ namespace ts {
1805518057 }
1805618058 }
1805718059 }
18058- const promisedType = getPromisedTypeOfPromise(containingType);
18059- if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
18060- errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType));
18060+ if (typeHasStaticProperty(propNode.escapedText, containingType)) {
18061+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_is_a_static_member_of_type_1, declarationNameToString(propNode), typeToString(containingType));
1806118062 }
1806218063 else {
18063- const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType);
18064- if (suggestion !== undefined) {
18065- const suggestedName = symbolName(suggestion);
18066- errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestedName);
18067- relatedInfo = suggestion.valueDeclaration && createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestedName);
18064+ const promisedType = getPromisedTypeOfPromise(containingType);
18065+ if (promisedType && getPropertyOfType(promisedType, propNode.escapedText)) {
18066+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await, declarationNameToString(propNode), typeToString(containingType));
1806818067 }
1806918068 else {
18070- errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
18069+ const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType);
18070+ if (suggestion !== undefined) {
18071+ const suggestedName = symbolName(suggestion);
18072+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestedName);
18073+ relatedInfo = suggestion.valueDeclaration && createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestedName);
18074+ }
18075+ else {
18076+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(containingType));
18077+ }
1807118078 }
1807218079 }
18073-
1807418080 const resultDiagnostic = createDiagnosticForNodeFromMessageChain(propNode, errorInfo);
1807518081 if (relatedInfo) {
1807618082 addRelatedInfo(resultDiagnostic, relatedInfo);
1807718083 }
1807818084 diagnostics.add(resultDiagnostic);
1807918085 }
1808018086
18087+ function typeHasStaticProperty(propName: __String, containingType: Type): boolean {
18088+ const prop = containingType.symbol && getPropertyOfType(getTypeOfSymbol(containingType.symbol), propName);
18089+ return prop !== undefined && prop.valueDeclaration && hasModifier(prop.valueDeclaration, ModifierFlags.Static);
18090+ }
18091+
1808118092 function getSuggestedSymbolForNonexistentProperty(name: Identifier | string, containingType: Type): Symbol | undefined {
1808218093 return getSpellingSuggestionForName(isString(name) ? name : idText(name), getPropertiesOfType(containingType), SymbolFlags.Value);
1808318094 }
0 commit comments