Skip to content

Commit efe5e3d

Browse files
committed
fix(46032): fix false positive in isSimpleTypeRelatedTo()
When the following conditions are satisfied, `isSimpleTypeRelatedTo(source, target)` returns true, which is false positive. - `strictNullChecks` is disabled - `source` is `undefined` - `target` is an empty intersection type which reduces to `never` by discriminants In this case, `isSimpleTypeRelatedTo()` should actually return `false`, which does *not* mean `source` doesn't relate to `target`, but rather tells the checker to further investigate their relation.
1 parent e1532a1 commit efe5e3d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17815,6 +17815,8 @@ namespace ts {
1781517815
const t = target.flags;
1781617816
if (t & TypeFlags.AnyOrUnknown || s & TypeFlags.Never || source === wildcardType) return true;
1781717817
if (t & TypeFlags.Never) return false;
17818+
// Intersection types that would be reduced to never may be passed as `target`, thus returning early.
17819+
if (t & TypeFlags.Intersection) return false;
1781817820
if (s & TypeFlags.StringLike && t & TypeFlags.String) return true;
1781917821
if (s & TypeFlags.StringLiteral && s & TypeFlags.EnumLiteral &&
1782017822
t & TypeFlags.StringLiteral && !(t & TypeFlags.EnumLiteral) &&

0 commit comments

Comments
 (0)