@@ -1518,12 +1518,14 @@ func (c *Checker) onFailedToResolveSymbol(errorLocation *ast.Node, name string,
15181518 suggestion := c.getSuggestedSymbolForNonexistentSymbol(errorLocation, name, meaning)
15191519 if suggestion != nil && !(suggestion.ValueDeclaration != nil && ast.IsAmbientModule(suggestion.ValueDeclaration) && ast.IsGlobalScopeAugmentation(suggestion.ValueDeclaration)) {
15201520 suggestionName := c.symbolToString(suggestion)
1521- message := core.IfElse(meaning == ast.SymbolFlagsNamespace, diagnostics.Cannot_find_namespace_0_Did_you_mean_1, diagnostics.Cannot_find_name_0_Did_you_mean_1)
1521+ isUncheckedJS := c.isUncheckedJSSuggestion(errorLocation, suggestion, false /*excludeClasses*/)
1522+ message := core.IfElse(meaning == ast.SymbolFlagsNamespace, diagnostics.Cannot_find_namespace_0_Did_you_mean_1,
1523+ core.IfElse(isUncheckedJS, diagnostics.Could_not_find_name_0_Did_you_mean_1, diagnostics.Cannot_find_name_0_Did_you_mean_1))
15221524 diagnostic := NewDiagnosticForNode(errorLocation, message, name, suggestionName)
15231525 if suggestion.ValueDeclaration != nil {
15241526 diagnostic.AddRelatedInfo(NewDiagnosticForNode(suggestion.ValueDeclaration, diagnostics.X_0_is_declared_here, suggestionName))
15251527 }
1526- c.diagnostics.Add( diagnostic)
1528+ c.addErrorOrSuggestion(!isUncheckedJS, diagnostic)
15271529 return
15281530 }
15291531 // And then fall back to unspecified "not found"
@@ -10873,11 +10875,10 @@ func (c *Checker) checkPropertyAccessExpressionOrQualifiedName(node *ast.Node, l
1087310875 if c.checkPrivateIdentifierPropertyAccess(leftType, right, lexicallyScopedSymbol) {
1087410876 return c.errorType
1087510877 }
10876- // !!!
10877- // containingClass := getContainingClassExcludingClassDecorators(right)
10878- // if containingClass && isPlainJSFile(ast.GetSourceFileOfNode(containingClass), c.compilerOptions.checkJs) {
10879- // c.grammarErrorOnNode(right, diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class, right.Text())
10880- // }
10878+ containingClass := getContainingClassExcludingClassDecorators(right)
10879+ if containingClass != nil && ast.IsPlainJSFile(ast.GetSourceFileOfNode(containingClass), c.compilerOptions.CheckJs) {
10880+ c.grammarErrorOnNode(right, diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class, right.Text())
10881+ }
1088110882 } else {
1088210883 isSetonlyAccessor := prop.Flags&ast.SymbolFlagsSetAccessor != 0 && prop.Flags&ast.SymbolFlagsGetAccessor == 0
1088310884 if isSetonlyAccessor && assignmentKind != AssignmentKindDefinite {
@@ -10904,6 +10905,10 @@ func (c *Checker) checkPropertyAccessExpressionOrQualifiedName(node *ast.Node, l
1090410905 indexInfo = c.getApplicableIndexInfoForName(apparentType, right.Text())
1090510906 }
1090610907 if indexInfo == nil {
10908+ isUncheckedJS := c.isUncheckedJSSuggestion(node, leftType.symbol, true /*excludeClasses*/)
10909+ if !isUncheckedJS && c.isJSLiteralType(leftType) {
10910+ return c.anyType
10911+ }
1090710912 if leftType.symbol == c.globalThisSymbol {
1090810913 globalSymbol := c.globalThisSymbol.Exports[right.Text()]
1090910914 if globalSymbol != nil && globalSymbol.Flags&ast.SymbolFlagsBlockScoped != 0 {
@@ -10914,7 +10919,7 @@ func (c *Checker) checkPropertyAccessExpressionOrQualifiedName(node *ast.Node, l
1091410919 return c.anyType
1091510920 }
1091610921 if right.Text() != "" && !c.checkAndReportErrorForExtendingInterface(node) {
10917- c.reportNonexistentProperty(right, core.IfElse(isThisTypeParameter(leftType), apparentType, leftType))
10922+ c.reportNonexistentProperty(right, core.IfElse(isThisTypeParameter(leftType), apparentType, leftType), isUncheckedJS )
1091810923 }
1091910924 return c.errorType
1092010925 }
@@ -11091,7 +11096,7 @@ func (c *Checker) checkPrivateIdentifierPropertyAccess(leftType *Type, right *as
1109111096 return false
1109211097}
1109311098
11094- func (c *Checker) reportNonexistentProperty(propNode *ast.Node, containingType *Type) {
11099+ func (c *Checker) reportNonexistentProperty(propNode *ast.Node, containingType *Type, isUncheckedJS bool ) {
1109511100 if ast.IsJSDocNameReferenceContext(propNode) {
1109611101 return
1109711102 }
@@ -11123,7 +11128,8 @@ func (c *Checker) reportNonexistentProperty(propNode *ast.Node, containingType *
1112311128 suggestion := c.getSuggestedSymbolForNonexistentProperty(propNode, containingType)
1112411129 if suggestion != nil {
1112511130 suggestedName := ast.SymbolName(suggestion)
11126- diagnostic = NewDiagnosticChainForNode(diagnostic, propNode, diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, missingProperty, container, suggestedName)
11131+ message := core.IfElse(isUncheckedJS, diagnostics.Property_0_may_not_exist_on_type_1_Did_you_mean_2, diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2)
11132+ diagnostic = NewDiagnosticChainForNode(diagnostic, propNode, message, missingProperty, container, suggestedName)
1112711133 if suggestion.ValueDeclaration != nil {
1112811134 diagnostic.AddRelatedInfo(NewDiagnosticForNode(suggestion.ValueDeclaration, diagnostics.X_0_is_declared_here, suggestedName))
1112911135 }
@@ -11140,7 +11146,7 @@ func (c *Checker) reportNonexistentProperty(propNode *ast.Node, containingType *
1114011146 }
1114111147 }
1114211148 }
11143- c.diagnostics.Add( diagnostic)
11149+ c.addErrorOrSuggestion(!isUncheckedJS || diagnostic.Code() != diagnostics.Property_0_may_not_exist_on_type_1_Did_you_mean_2.Code(), diagnostic)
1114411150}
1114511151
1114611152func (c *Checker) getSuggestedLibForNonExistentProperty(missingProperty string, containingType *Type) string {
@@ -12609,7 +12615,8 @@ func (c *Checker) checkInExpression(left *ast.Expression, right *ast.Expression,
1260912615 // Unlike in 'checkPrivateIdentifierExpression' we now have access to the RHS type
1261012616 // which provides us with the opportunity to emit more detailed errors
1261112617 if c.symbolNodeLinks.Get(left).resolvedSymbol == nil && ast.GetContainingClass(left) != nil {
12612- c.reportNonexistentProperty(left, rightType)
12618+ isUncheckedJS := c.isUncheckedJSSuggestion(left, rightType.symbol, true /*excludeClasses*/)
12619+ c.reportNonexistentProperty(left, rightType, isUncheckedJS)
1261312620 }
1261412621 } else {
1261512622 // The type of the left operand must be assignable to string, number, or symbol.
@@ -12714,6 +12721,9 @@ func (c *Checker) checkObjectLiteral(node *ast.Node, checkMode CheckMode) *Type
1271412721 }
1271512722 result := c.newAnonymousType(node.Symbol(), propertiesTable, nil, nil, indexInfos)
1271612723 result.objectFlags |= objectFlags | ObjectFlagsObjectLiteral | ObjectFlagsContainsObjectOrArrayLiteral
12724+ if contextualType == nil && ast.IsInJSFile(node) && !ast.IsInJsonFile(node) {
12725+ result.objectFlags |= ObjectFlagsJSLiteral
12726+ }
1271712727 if patternWithComputedProperties {
1271812728 result.objectFlags |= ObjectFlagsObjectLiteralPatternWithComputedProperties
1271912729 }
@@ -17598,6 +17608,10 @@ func (c *Checker) widenTypeForVariableLikeDeclaration(t *Type, declaration *ast.
1759817608}
1759917609
1760017610func (c *Checker) reportImplicitAny(declaration *ast.Node, t *Type, wideningKind WideningKind) {
17611+ if ast.IsInJSFile(declaration) && !ast.IsCheckJSEnabledForFile(ast.GetSourceFileOfNode(declaration), c.compilerOptions) {
17612+ // Only report implicit any errors/suggestions in TS and ts-check JS files
17613+ return
17614+ }
1760117615 typeAsString := c.TypeToString(c.getWidenedType(t))
1760217616 var diagnostic *diagnostics.Message
1760317617 switch declaration.Kind {
@@ -26321,6 +26335,9 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy
2632126335 if indexType.flags&TypeFlagsNever != 0 {
2632226336 return c.neverType
2632326337 }
26338+ if c.isJSLiteralType(objectType) {
26339+ return c.anyType
26340+ }
2632426341 if accessExpression != nil && !isConstEnumObjectType(objectType) {
2632526342 if isObjectLiteralType(objectType) {
2632626343 if c.noImplicitAny && indexType.flags&(TypeFlagsStringLiteral|TypeFlagsNumberLiteral) != 0 {
@@ -26378,6 +26395,9 @@ func (c *Checker) getPropertyTypeForIndexType(originalObjectType *Type, objectTy
2637826395 if accessFlags&AccessFlagsAllowMissing != 0 && isObjectLiteralType(objectType) {
2637926396 return c.undefinedType
2638026397 }
26398+ if c.isJSLiteralType(objectType) {
26399+ return c.anyType
26400+ }
2638126401 if accessNode != nil {
2638226402 indexNode := getIndexNodeForAccessExpression(accessNode)
2638326403 if indexNode.Kind != ast.KindBigIntLiteral && indexType.flags&(TypeFlagsStringLiteral|TypeFlagsNumberLiteral) != 0 {
0 commit comments