@@ -16639,7 +16639,7 @@ namespace ts {
16639
16639
if (!targetProperty) continue outer;
16640
16640
if (sourceProperty === targetProperty) continue;
16641
16641
// We compare the source property to the target in the context of a single discriminant type.
16642
- const related = propertyRelatedTo(source, target, sourceProperty, targetProperty, _ => combination[i], /*reportErrors*/ false, IntersectionState.None);
16642
+ const related = propertyRelatedTo(source, target, sourceProperty, targetProperty, _ => combination[i], /*reportErrors*/ false, IntersectionState.None, /*skipOptional*/ strictNullChecks || relation === comparableRelation );
16643
16643
// If the target property could not be found, or if the properties were not related,
16644
16644
// then this constituent is not a match.
16645
16645
if (!related) {
@@ -16737,7 +16737,7 @@ namespace ts {
16737
16737
}
16738
16738
}
16739
16739
16740
- function propertyRelatedTo(source: Type, target: Type, sourceProp: Symbol, targetProp: Symbol, getTypeOfSourceProperty: (sym: Symbol) => Type, reportErrors: boolean, intersectionState: IntersectionState): Ternary {
16740
+ function propertyRelatedTo(source: Type, target: Type, sourceProp: Symbol, targetProp: Symbol, getTypeOfSourceProperty: (sym: Symbol) => Type, reportErrors: boolean, intersectionState: IntersectionState, skipOptional: boolean ): Ternary {
16741
16741
const sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp);
16742
16742
const targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp);
16743
16743
if (sourcePropFlags & ModifierFlags.Private || targetPropFlags & ModifierFlags.Private) {
@@ -16780,7 +16780,7 @@ namespace ts {
16780
16780
return Ternary.False;
16781
16781
}
16782
16782
// When checking for comparability, be more lenient with optional properties.
16783
- if (relation !== comparableRelation && sourceProp.flags & SymbolFlags.Optional && !(targetProp.flags & SymbolFlags.Optional)) {
16783
+ if (!skipOptional && sourceProp.flags & SymbolFlags.Optional && !(targetProp.flags & SymbolFlags.Optional)) {
16784
16784
// TypeScript 1.0 spec (April 2014): 3.8.3
16785
16785
// S is a subtype of a type T, and T is a supertype of S if ...
16786
16786
// S' and T are object types and, for each member M in T..
@@ -16910,7 +16910,7 @@ namespace ts {
16910
16910
if (!(targetProp.flags & SymbolFlags.Prototype) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
16911
16911
const sourceProp = getPropertyOfType(source, name);
16912
16912
if (sourceProp && sourceProp !== targetProp) {
16913
- const related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
16913
+ const related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation );
16914
16914
if (!related) {
16915
16915
return Ternary.False;
16916
16916
}
0 commit comments