Skip to content

Commit c068103

Browse files
committed
Fix getNarrowedType so that only strings and numbers are not processed
1 parent d4b4ad1 commit c068103

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24735,20 +24735,15 @@ namespace ts {
2473524735
// If the current type is a union type, remove all constituents that couldn't be instances of
2473624736
// the candidate type. If one or more constituents remain, return a union of those.
2473724737
if (type.flags & TypeFlags.Union) {
24738+
let assignableType = filterType(type, t => isRelated(t, candidate));
2473824739
if(candidate.flags & TypeFlags.Union){
24739-
const assignableType = mapType(type, type => {
24740-
if (!!(type.flags & TypeFlags.String) || !!(type.flags & TypeFlags.Number)) {
24741-
return filterType(candidate, candidate => isTypeSubtypeOf(candidate, type));
24742-
}
24743-
else {
24744-
return isRelated(type, candidate) ? type : neverType;
24745-
}
24740+
const unionAssignableType = mapType(type, type => {
24741+
return filterType(candidate, candidate => isRelated(candidate, type));
2474624742
});
24747-
if (!(assignableType.flags & TypeFlags.Never)) {
24748-
return assignableType;
24743+
if (!isTypeSubsetOf(unionAssignableType, assignableType)) {
24744+
assignableType = unionAssignableType;
2474924745
}
2475024746
}
24751-
const assignableType = filterType(type, t => isRelated(t, candidate));
2475224747
if (!(assignableType.flags & TypeFlags.Never)) {
2475324748
return assignableType;
2475424749
}

0 commit comments

Comments
 (0)