Skip to content

Commit d1d487c

Browse files
committed
Improve naming and refactor for readability
1 parent 0b911d5 commit d1d487c

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/compiler/checker.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8701,7 +8701,7 @@ namespace ts {
87018701
let expandingFlags: number;
87028702
let depth = 0;
87038703
let overflow = false;
8704-
let dynamicDisableWeakTypeErrors = false;
8704+
let disableWeakTypeErrors = false;
87058705

87068706
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
87078707

@@ -8981,33 +8981,32 @@ namespace ts {
89818981
function typeRelatedToEachType(source: Type, target: IntersectionType, reportErrors: boolean): Ternary {
89828982
let result = Ternary.True;
89838983
const targetTypes = target.types;
8984-
const saveDynamicDisableWeakTypeErrors = dynamicDisableWeakTypeErrors;
8985-
dynamicDisableWeakTypeErrors = true;
8984+
const saveDisableWeakTypeErrors = disableWeakTypeErrors;
8985+
disableWeakTypeErrors = true;
89868986
for (const targetType of targetTypes) {
89878987
const related = isRelatedTo(source, targetType, reportErrors);
89888988
if (!related) {
8989-
dynamicDisableWeakTypeErrors = saveDynamicDisableWeakTypeErrors;
8989+
disableWeakTypeErrors = saveDisableWeakTypeErrors;
89908990
return Ternary.False;
89918991
}
89928992
result &= related;
89938993
}
8994-
dynamicDisableWeakTypeErrors = saveDynamicDisableWeakTypeErrors;
8995-
if (source !== globalObjectType && getPropertiesOfType(source).length > 0 && every(target.types, isWeak)) {
8996-
let found = false;
8997-
for (const property of getPropertiesOfType(source)) {
8998-
if (isKnownProperty(target, property.name, /*isComparingJsxAttributes*/ false)) {
8999-
found = true;
9000-
break;
9001-
}
9002-
}
9003-
if (!found) {
9004-
if (reportErrors) {
9005-
reportError(Diagnostics.Weak_type_0_has_no_properties_in_common_with_1, typeToString(target), typeToString(source));
9006-
}
9007-
return Ternary.False;
9008-
}
8994+
disableWeakTypeErrors = saveDisableWeakTypeErrors;
8995+
return reportAssignmentToWeakIntersection(source, target, reportErrors) ? Ternary.False : result;
8996+
}
8997+
8998+
function reportAssignmentToWeakIntersection(source: Type, target: IntersectionType, reportErrors: boolean) {
8999+
const needsWeakTypeCheck = source !== globalObjectType && getPropertiesOfType(source).length > 0 && every(target.types, isWeak);
9000+
if (!needsWeakTypeCheck) {
9001+
return false;
90099002
}
9010-
return result;
9003+
const hasSharedProperty = forEach(
9004+
getPropertiesOfType(source),
9005+
p => isKnownProperty(target, p.name, /*isComparingJsxAttributes*/ false));
9006+
if (!hasSharedProperty && reportErrors) {
9007+
reportError(Diagnostics.Weak_type_0_has_no_properties_in_common_with_1, typeToString(target), typeToString(source));
9008+
}
9009+
return !hasSharedProperty;
90119010
}
90129011

90139012
function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary {
@@ -9379,7 +9378,7 @@ namespace ts {
93799378
}
93809379
}
93819380
}
9382-
if (!foundMatchingProperty && !dynamicDisableWeakTypeErrors && source !== globalObjectType && getPropertiesOfType(source).length > 0) {
9381+
if (!foundMatchingProperty && !disableWeakTypeErrors && source !== globalObjectType && getPropertiesOfType(source).length > 0) {
93839382
if (reportErrors) {
93849383
reportError(Diagnostics.Weak_type_0_has_no_properties_in_common_with_1, typeToString(target), typeToString(source));
93859384
}

0 commit comments

Comments
 (0)