Fix isUnitLikeType to (again) handle tagged literal types (#51545)

* Fix isUnitLikeType to (again) handle tagged literal types

* Add regression test
This commit is contained in:
Anders Hejlsberg
2022-11-30 13:30:52 -08:00
committed by GitHub
parent 16edc29bc9
commit 8036b149a4
6 changed files with 191 additions and 1 deletions
+4 -1
View File
@@ -22633,7 +22633,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function isUnitLikeType(type: Type): boolean {
return isUnitType(getBaseConstraintOrType(type));
// Intersections that reduce to 'never' (e.g. 'T & null' where 'T extends {}') are not unit types.
const t = getBaseConstraintOrType(type);
// Scan intersections such that tagged literal types are considered unit types.
return t.flags & TypeFlags.Intersection ? some((t as IntersectionType).types, isUnitType) : isUnitType(t);
}
function extractUnitType(type: Type) {