-
-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathis-union.d.ts
More file actions
40 lines (34 loc) · 848 Bytes
/
is-union.d.ts
File metadata and controls
40 lines (34 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.
@example
```
import type {IsUnion} from 'type-fest';
type A = IsUnion<string | number>;
//=> true
type B = IsUnion<string>;
//=> false
```
*/
export type IsUnion<T> = InternalIsUnion<T>;
/**
The actual implementation of `IsUnion`.
*/
type InternalIsUnion<T, U = T> =
(
IsNever<T> extends true
? false
: T extends any
? IsEqual<U, T> extends true
? false
: true
: never
) extends infer Result
// In some cases `Result` will return `false | true` which is `boolean`,
// that means `T` has at least two types and it's a union type,
// so we will return `true` instead of `boolean`.
? boolean extends Result ? true
: Result
: never; // Should never happen
export {};