From 40a5fc1189d7a6591fe125ab5716af317829aa8d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 28 Aug 2022 08:11:10 -0700 Subject: [PATCH] Handle intersections in isGenericTypeWithoutNullableConstraint --- src/compiler/checker.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f1dacf1f1eee2..2609d14d0fd2f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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) {