Skip to content

Commit c853d7c

Browse files
Don't elaborate on primitives at all.
1 parent 12a201c commit c853d7c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10633,13 +10633,14 @@ namespace ts {
1063310633

1063410634
// Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
1063510635
// 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.
1063710637
// 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 &&
1064310644
(target as UnionType).types.length <= 3 && maybeTypeOfKind(target, TypeFlags.Nullable)) {
1064410645
const nullStrippedTarget = extractTypesOfKind(target, ~TypeFlags.Nullable);
1064510646
if (!(nullStrippedTarget.flags & (TypeFlags.Union | TypeFlags.Never))) {

0 commit comments

Comments
 (0)