@@ -10633,13 +10633,14 @@ namespace ts {
10633
10633
10634
10634
// Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
10635
10635
// If so, reporting the `null` and `undefined` in the type is hardly useful.
10636
- // First, see if we're even relating an atomic type to a union.
10636
+ // First, see if we're even relating an object type to a union.
10637
10637
// Then see if the target is stripped down to a single non-union type.
10638
- // We actually want to remove null and undefined naively here (rather than getNonNullableType),
10639
- // since we don't want to end up with a worse error like "`Foo` is not assignable to `NonNullable<T>`"
10640
- // when dealing with generics.
10641
- if (target.flags & TypeFlags.Union &&
10642
- source.flags & ((TypeFlags.Primitive | TypeFlags.Object) & ~(TypeFlags.Nullable | TypeFlags.Void)) &&
10638
+ // Note
10639
+ // * We actually want to remove null and undefined naively here (rather than using getNonNullableType),
10640
+ // since we don't want to end up with a worse error like "`Foo` is not assignable to `NonNullable<T>`"
10641
+ // when dealing with generics.
10642
+ // * We also don't deal with primitive source types, since we already halt elaboration below.
10643
+ if (target.flags & TypeFlags.Union && source.flags & TypeFlags.Object &&
10643
10644
(target as UnionType).types.length <= 3 && maybeTypeOfKind(target, TypeFlags.Nullable)) {
10644
10645
const nullStrippedTarget = extractTypesOfKind(target, ~TypeFlags.Nullable);
10645
10646
if (!(nullStrippedTarget.flags & (TypeFlags.Union | TypeFlags.Never))) {
0 commit comments