Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/is-union.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {IsNever} from './is-never.d.ts';
import type {IsEqual} from './is-equal.d.ts';

/**
Returns a boolean for whether the given type is a union.
Expand All @@ -24,7 +25,7 @@ type InternalIsUnion<T, U = T> =
IsNever<T> extends true
? false
: T extends any
? [U] extends [T]
? IsEqual<U, T> extends true
? false
: true
: never
Expand Down
9 changes: 9 additions & 0 deletions test-d/is-union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ expectType<IsUnion<'foo' | 'bar'>>(true);
expectType<IsUnion<'foo' | 'bar' | 1>>(true);
expectType<IsUnion<'foo' | 1>>(true);
expectType<IsUnion<[] | {}>>(true);

type TestUnion =
// Here, the entire union extends both the individual members:
// So, `TestUnion` extends `{opt?: number; a: number; b: string}`, and
// `TestUnion` extends `{a: number; b: string}`.
| {opt?: number; a: number; b: string}
| {a: number; b: string};

expectType<IsUnion<TestUnion>>(true);