Handle intersections in isGenericTypeWithoutNullableConstraint (#50497)

* Handle intersections in isGenericTypeWithoutNullableConstraint

* Add regression test
This commit is contained in:
Anders Hejlsberg
2022-08-29 09:24:13 -07:00
committed by GitHub
parent ed6889cd5b
commit 6d170b490d
6 changed files with 76 additions and 2 deletions

View File

@@ -25789,8 +25789,10 @@ namespace ts {
!!(type.flags & TypeFlags.Instantiable && getBaseConstraintOrType(type).flags & (TypeFlags.Nullable | TypeFlags.Union));
}
function isGenericTypeWithoutNullableConstraint(type: Type) {
return !!(type.flags & TypeFlags.Instantiable && !maybeTypeOfKind(getBaseConstraintOrType(type), TypeFlags.Nullable));
function isGenericTypeWithoutNullableConstraint(type: Type): boolean {
return type.flags & TypeFlags.Intersection ?
some((type as IntersectionType).types, isGenericTypeWithoutNullableConstraint) :
!!(type.flags & TypeFlags.Instantiable && !maybeTypeOfKind(getBaseConstraintOrType(type), TypeFlags.Nullable));
}
function hasContextualTypeWithNoGenericTypes(node: Node, checkMode: CheckMode | undefined) {