@@ -16540,7 +16540,7 @@ namespace ts {
16540
16540
if (!targetProperty) continue outer;
16541
16541
if (sourceProperty === targetProperty) continue;
16542
16542
// We compare the source property to the target in the context of a single discriminant type.
16543
- const related = propertyRelatedTo(source, target, sourceProperty, targetProperty, _ => combination[i], /*reportErrors*/ false, IntersectionState.None);
16543
+ const related = propertyRelatedTo(source, target, sourceProperty, targetProperty, _ => combination[i], /*reportErrors*/ false, IntersectionState.None, /*skipOptional*/ strictNullChecks || relation === comparableRelation );
16544
16544
// If the target property could not be found, or if the properties were not related,
16545
16545
// then this constituent is not a match.
16546
16546
if (!related) {
@@ -16638,7 +16638,7 @@ namespace ts {
16638
16638
}
16639
16639
}
16640
16640
16641
- function propertyRelatedTo(source: Type, target: Type, sourceProp: Symbol, targetProp: Symbol, getTypeOfSourceProperty: (sym: Symbol) => Type, reportErrors: boolean, intersectionState: IntersectionState): Ternary {
16641
+ function propertyRelatedTo(source: Type, target: Type, sourceProp: Symbol, targetProp: Symbol, getTypeOfSourceProperty: (sym: Symbol) => Type, reportErrors: boolean, intersectionState: IntersectionState, skipOptional: boolean ): Ternary {
16642
16642
const sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp);
16643
16643
const targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp);
16644
16644
if (sourcePropFlags & ModifierFlags.Private || targetPropFlags & ModifierFlags.Private) {
@@ -16681,7 +16681,7 @@ namespace ts {
16681
16681
return Ternary.False;
16682
16682
}
16683
16683
// When checking for comparability, be more lenient with optional properties.
16684
- if (relation !== comparableRelation && sourceProp.flags & SymbolFlags.Optional && !(targetProp.flags & SymbolFlags.Optional)) {
16684
+ if (!skipOptional && sourceProp.flags & SymbolFlags.Optional && !(targetProp.flags & SymbolFlags.Optional)) {
16685
16685
// TypeScript 1.0 spec (April 2014): 3.8.3
16686
16686
// S is a subtype of a type T, and T is a supertype of S if ...
16687
16687
// S' and T are object types and, for each member M in T..
@@ -16811,7 +16811,7 @@ namespace ts {
16811
16811
if (!(targetProp.flags & SymbolFlags.Prototype) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
16812
16812
const sourceProp = getPropertyOfType(source, name);
16813
16813
if (sourceProp && sourceProp !== targetProp) {
16814
- const related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
16814
+ const related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation );
16815
16815
if (!related) {
16816
16816
return Ternary.False;
16817
16817
}
0 commit comments