mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Allow intersections (and substitutions) to be checks against discriminable unions (#36663)
This commit is contained in:
@@ -15901,7 +15901,7 @@ namespace ts {
|
||||
// with respect to T. We do not report errors here, as we will use the existing
|
||||
// error result from checking each constituent of the union.
|
||||
if (source.flags & (TypeFlags.Object | TypeFlags.Intersection) && target.flags & TypeFlags.Union) {
|
||||
const objectOnlyTarget = extractTypesOfKind(target, TypeFlags.Object);
|
||||
const objectOnlyTarget = extractTypesOfKind(target, TypeFlags.Object | TypeFlags.Intersection | TypeFlags.Substitution);
|
||||
if (objectOnlyTarget.flags & TypeFlags.Union) {
|
||||
const result = typeRelatedToDiscriminatedType(source, objectOnlyTarget as UnionType);
|
||||
if (result) {
|
||||
@@ -15998,7 +15998,7 @@ namespace ts {
|
||||
// NOTE: See ~/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithDiscriminatedUnion.ts
|
||||
// for examples.
|
||||
|
||||
const sourceProperties = getPropertiesOfObjectType(source);
|
||||
const sourceProperties = getPropertiesOfType(source);
|
||||
const sourcePropertiesFiltered = findDiscriminantProperties(sourceProperties, target);
|
||||
if (!sourcePropertiesFiltered) return Ternary.False;
|
||||
|
||||
@@ -16037,7 +16037,7 @@ namespace ts {
|
||||
outer: for (const type of target.types) {
|
||||
for (let i = 0; i < sourcePropertiesFiltered.length; i++) {
|
||||
const sourceProperty = sourcePropertiesFiltered[i];
|
||||
const targetProperty = getPropertyOfObjectType(type, sourceProperty.escapedName);
|
||||
const targetProperty = getPropertyOfType(type, sourceProperty.escapedName);
|
||||
if (!targetProperty) continue outer;
|
||||
if (sourceProperty === targetProperty) continue;
|
||||
// We compare the source property to the target in the context of a single discriminant type.
|
||||
|
||||
Reference in New Issue
Block a user