@@ -2063,7 +2063,7 @@ namespace ts {
2063
2063
if (isGlobalScopeAugmentationDeclaration) {
2064
2064
suggestion = undefined;
2065
2065
}
2066
- if (originalLocation && isBadUncheckedJSSuggestion(lastLocation, /*parent */ undefined, suggestion?.valueDeclaration ? [suggestion.valueDeclaration] : [] )) {
2066
+ if (originalLocation && isExcludedJSError(originalLocation, suggestion, /*forbidClasses */ false )) {
2067
2067
suggestion = undefined;
2068
2068
}
2069
2069
if (suggestion) {
@@ -27455,8 +27455,8 @@ namespace ts {
27455
27455
if (!prop) {
27456
27456
const indexInfo = !isPrivateIdentifier(right) && (assignmentKind === AssignmentKind.None || !isGenericObjectType(leftType) || isThisTypeParameter(leftType)) ? getIndexInfoOfType(apparentType, IndexKind.String) : undefined;
27457
27457
if (!(indexInfo && indexInfo.type)) {
27458
- const isBadJSSuggestion = isBadUncheckedJSSuggestion (node, leftType.symbol, leftType.symbol?.declarations );
27459
- if (isBadJSSuggestion === undefined ? isJSLiteralType(leftType) : isBadJSSuggestion ) {
27458
+ const isExcludedError = isExcludedJSError (node, leftType.symbol, /*forbidClasses*/ true );
27459
+ if (isExcludedError === undefined ? isJSLiteralType(leftType) : isExcludedError ) {
27460
27460
return anyType;
27461
27461
}
27462
27462
if (leftType.symbol === globalThisSymbol) {
@@ -27504,17 +27504,20 @@ namespace ts {
27504
27504
27505
27505
/**
27506
27506
* Only applies to unchecked JS files without checkJS, // @ts-check or // @ts-nocheck
27507
- * @returns undefined when not applicable, true for bad suggestions, false for good ones
27508
- * TODO: Should probably only pass one declaration
27507
+ * @returns undefined when not applicable, true for excluded errors, false for included ones
27508
+ *
27509
+ * An error is excluded when it:
27510
+ * - Is from a global file that is different from the reference file, or
27511
+ * - (optionally) Is a class, or is a this.x property access expression
27509
27512
*/
27510
- function isBadUncheckedJSSuggestion (node: Node | undefined, parent : Symbol | undefined, declarations: Node[] | undefined ): boolean | undefined {
27513
+ function isExcludedJSError (node: Node | undefined, suggestion : Symbol | undefined, excludeClasses: boolean ): boolean | undefined {
27511
27514
const file = getSourceFileOfNode(node);
27512
27515
if (file) {
27513
27516
if (compilerOptions.checkJs === undefined && !file.checkJsDirective && (file.scriptKind === ScriptKind.JS || file.scriptKind === ScriptKind.JSX)) {
27514
- const parentFile = forEach(declarations, getSourceFileOfNode);
27515
- return file !== parentFile && !!parentFile && isGlobalSourceFile(parentFile )
27516
- || !!(parent && parent .flags & SymbolFlags.Class)
27517
- || !!node && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword;
27517
+ const declarationFile = forEach(suggestion?. declarations, getSourceFileOfNode);
27518
+ return file !== declarationFile && !!declarationFile && isGlobalSourceFile(declarationFile )
27519
+ || !!(excludeClasses && suggestion && suggestion .flags & SymbolFlags.Class)
27520
+ || !!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword;
27518
27521
}
27519
27522
}
27520
27523
}
0 commit comments