Skip to content

Commit 3206f5f

Browse files
committed
When inferring from XXX to T | XXX make no inferece for T (instead of never)
1 parent b822def commit 3206f5f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15515,16 +15515,18 @@ namespace ts {
1551515515
// removing the identically matched constituents. For example, when inferring from
1551615516
// 'string | string[]' to 'string | T' we reduce the types to 'string[]' and 'T'.
1551715517
if (matchingTypes) {
15518-
source = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>source, matchingTypes);
15519-
target = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, matchingTypes);
15518+
const s = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>source, matchingTypes);
15519+
const t = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, matchingTypes);
15520+
if (!(s && t)) return;
15521+
source = s;
15522+
target = t;
1552015523
}
1552115524
}
1552215525
else if (target.flags & TypeFlags.Union && !(target.flags & TypeFlags.EnumLiteral) || target.flags & TypeFlags.Intersection) {
1552315526
const matched = findMatchedType(source, <UnionOrIntersectionType>target);
1552415527
if (matched) {
1552515528
inferFromTypes(matched, matched);
15526-
source = target.flags & TypeFlags.Union ? neverType : unknownType;
15527-
target = removeTypesFromUnionOrIntersection(<UnionOrIntersectionType>target, [matched]);
15529+
return;
1552815530
}
1552915531
}
1553015532
else if (target.flags & (TypeFlags.IndexedAccess | TypeFlags.Substitution)) {
@@ -15993,7 +15995,7 @@ namespace ts {
1599315995
reducedTypes.push(t);
1599415996
}
1599515997
}
15996-
return type.flags & TypeFlags.Union ? getUnionType(reducedTypes) : getIntersectionType(reducedTypes);
15998+
return reducedTypes.length ? type.flags & TypeFlags.Union ? getUnionType(reducedTypes) : getIntersectionType(reducedTypes) : undefined;
1599715999
}
1599816000

1599916001
function hasPrimitiveConstraint(type: TypeParameter): boolean {

0 commit comments

Comments
 (0)