@@ -20354,7 +20354,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20354
20354
20355
20355
function getBestMatchIndexedAccessTypeOrUndefined(source: Type, target: Type, nameType: Type) {
20356
20356
if (target.flags & TypeFlags.Union) {
20357
- const best = getBestMatchingType(source, target as UnionType);
20357
+ const best = getBestMatchingType(source, target as UnionType, /*matchSingleOverlappy*/ false );
20358
20358
if (best) {
20359
20359
return getIndexedAccessTypeOrUndefined(best, nameType);
20360
20360
}
@@ -21985,7 +21985,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
21985
21985
}
21986
21986
if (reportErrors) {
21987
21987
// Elaborate only if we can find a best matching type in the target
21988
- const bestMatchingType = getBestMatchingType(source, target, isRelatedTo, /*singleOverlappy */ true);
21988
+ const bestMatchingType = getBestMatchingType(source, target, /*matchSingleOverlappy */ true, isRelatedTo );
21989
21989
if (bestMatchingType) {
21990
21990
isRelatedTo(source, bestMatchingType, RecursionFlags.Target, /*reportErrors*/ true, /*headMessage*/ undefined, intersectionState);
21991
21991
}
@@ -23712,11 +23712,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
23712
23712
return getPropertiesOfType(type).filter(targetProp => containsMissingType(getTypeOfSymbol(targetProp)));
23713
23713
}
23714
23714
23715
- function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable, singleOverlappy = false ) {
23715
+ function getBestMatchingType(source: Type, target: UnionOrIntersectionType, matchSingleOverlappy: boolean, isRelatedTo = compareTypesAssignable ) {
23716
23716
return findMatchingDiscriminantType(source, target, isRelatedTo) ||
23717
23717
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
23718
23718
findBestTypeForInvokable(source, target) ||
23719
- findMostOverlappyType(source, filterTypesForObjectLiteralMatch(source, target), singleOverlappy );
23719
+ findMostOverlappyType(source, filterTypesForObjectLiteralMatch(source, target), /*matchSingle*/ matchSingleOverlappy );
23720
23720
}
23721
23721
23722
23722
function discriminateTypeByDiscriminableItems(target: UnionType, discriminators: (readonly [() => Type, __String])[], related: (source: Type, target: Type) => boolean | Ternary) {
@@ -50924,7 +50924,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
50924
50924
}
50925
50925
}
50926
50926
50927
- function findMostOverlappyType(source: Type, target: Type, singleOverlappy : boolean) {
50927
+ function findMostOverlappyType(source: Type, target: Type, matchSingle : boolean) {
50928
50928
if (!(target.flags & TypeFlags.UnionOrIntersection)) {
50929
50929
return target;
50930
50930
}
@@ -50944,8 +50944,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
50944
50944
// needed to elaborate between two generic mapped types anyway.
50945
50945
const len = overlap.flags & TypeFlags.Union ? countWhere((overlap as UnionType).types, isUnitType) : 1;
50946
50946
if (len >= matchingCount) {
50947
- if (len > matchingCount) {
50948
- bestMatches.length = 0;
50947
+ if (len > matchingCount || matchSingle ) {
50948
+ bestMatches.length = 0;
50949
50949
}
50950
50950
bestMatches = append(bestMatches, type);
50951
50951
matchingCount = len;
@@ -50954,7 +50954,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
50954
50954
}
50955
50955
}
50956
50956
}
50957
- return bestMatches.length ? singleOverlappy ? last(bestMatches) : getUnionType(bestMatches) : undefined;
50957
+ return bestMatches.length ? getUnionType(bestMatches) : undefined;
50958
50958
}
50959
50959
50960
50960
function filterPrimitivesIfContainsNonPrimitive(type: UnionType) {
0 commit comments