Fixed an issue with in not being able to be used on narrowed down expression of a generic nullable type (#51502)

* Fixed an issue with `in` not being able to be used on narrowed down expression of a generic nullable type

* Add another test case from a new issue

* Move the fix to `hasEmptyObjectIntersection`
This commit is contained in:
Mateusz Burzyński
2022-11-22 07:03:58 +01:00
committed by GitHub
parent 12d7e4bdbf
commit 5cd2d975c3
10 changed files with 191 additions and 1 deletions
+1 -1
View File
@@ -34998,7 +34998,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function hasEmptyObjectIntersection(type: Type): boolean {
return someType(type, t => t === unknownEmptyObjectType || !!(t.flags & TypeFlags.Intersection) && some((t as IntersectionType).types, isEmptyAnonymousObjectType));
return someType(type, t => t === unknownEmptyObjectType || !!(t.flags & TypeFlags.Intersection) && isEmptyAnonymousObjectType(getBaseConstraintOrType(t)));
}
function checkInExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type {