mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 01:43:59 -05:00
Do not check excess properties for multi-discriminant unions
This commit is contained in:
@@ -9028,20 +9028,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
function findMatchingDiscriminantType(source: Type, target: UnionOrIntersectionType) {
|
||||
const sourceProperties = getPropertiesOfObjectType(source);
|
||||
let match: Type;
|
||||
const sourceProperties = getPropertiesOfObjectType(source);
|
||||
if (sourceProperties) {
|
||||
for (const sourceProperty of sourceProperties) {
|
||||
if (isDiscriminantProperty(target, sourceProperty.name)) {
|
||||
const sourceType = getTypeOfSymbol(sourceProperty);
|
||||
for (const type of target.types) {
|
||||
const targetType = getTypeOfPropertyOfType(type, sourceProperty.name);
|
||||
if (targetType && isRelatedTo(sourceType, targetType)) {
|
||||
if (match) {
|
||||
return undefined;
|
||||
}
|
||||
match = type;
|
||||
const sourceProperty = findSingleDiscriminantProperty(sourceProperties, target);
|
||||
if (sourceProperty) {
|
||||
const sourceType = getTypeOfSymbol(sourceProperty);
|
||||
for (const type of target.types) {
|
||||
const targetType = getTypeOfPropertyOfType(type, sourceProperty.name);
|
||||
if (targetType && isRelatedTo(sourceType, targetType)) {
|
||||
if (match) {
|
||||
return undefined;
|
||||
}
|
||||
match = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10839,6 +10838,19 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function findSingleDiscriminantProperty(sourceProperties: Symbol[], target: Type): Symbol | undefined {
|
||||
let result: Symbol;
|
||||
for (const sourceProperty of sourceProperties) {
|
||||
if (isDiscriminantProperty(target, sourceProperty.name)) {
|
||||
if (result) {
|
||||
return undefined;
|
||||
}
|
||||
result = sourceProperty;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function isOrContainsMatchingReference(source: Node, target: Node) {
|
||||
return isMatchingReference(source, target) || containsMatchingReference(source, target);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user