@@ -8701,7 +8701,7 @@ namespace ts {
8701
8701
let expandingFlags: number;
8702
8702
let depth = 0;
8703
8703
let overflow = false;
8704
- let dynamicDisableWeakTypeErrors = false;
8704
+ let disableWeakTypeErrors = false;
8705
8705
8706
8706
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
8707
8707
@@ -8981,33 +8981,32 @@ namespace ts {
8981
8981
function typeRelatedToEachType(source: Type, target: IntersectionType, reportErrors: boolean): Ternary {
8982
8982
let result = Ternary.True;
8983
8983
const targetTypes = target.types;
8984
- const saveDynamicDisableWeakTypeErrors = dynamicDisableWeakTypeErrors ;
8985
- dynamicDisableWeakTypeErrors = true;
8984
+ const saveDisableWeakTypeErrors = disableWeakTypeErrors ;
8985
+ disableWeakTypeErrors = true;
8986
8986
for (const targetType of targetTypes) {
8987
8987
const related = isRelatedTo(source, targetType, reportErrors);
8988
8988
if (!related) {
8989
- dynamicDisableWeakTypeErrors = saveDynamicDisableWeakTypeErrors ;
8989
+ disableWeakTypeErrors = saveDisableWeakTypeErrors ;
8990
8990
return Ternary.False;
8991
8991
}
8992
8992
result &= related;
8993
8993
}
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;
9009
9002
}
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;
9011
9010
}
9012
9011
9013
9012
function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary {
@@ -9379,7 +9378,7 @@ namespace ts {
9379
9378
}
9380
9379
}
9381
9380
}
9382
- if (!foundMatchingProperty && !dynamicDisableWeakTypeErrors && source !== globalObjectType && getPropertiesOfType(source).length > 0) {
9381
+ if (!foundMatchingProperty && !disableWeakTypeErrors && source !== globalObjectType && getPropertiesOfType(source).length > 0) {
9383
9382
if (reportErrors) {
9384
9383
reportError(Diagnostics.Weak_type_0_has_no_properties_in_common_with_1, typeToString(target), typeToString(source));
9385
9384
}
0 commit comments