-
-
Notifications
You must be signed in to change notification settings - Fork 722
Expand file tree
/
Copy pathis-boolean-literal.d.ts
More file actions
39 lines (30 loc) · 868 Bytes
/
Copy pathis-boolean-literal.d.ts
File metadata and controls
39 lines (30 loc) · 868 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
import type {CollapseLiterals, UnwrapBrand} from './internal/object.d.ts';
import type {IfNotAnyOrNever} from './internal/type.d.ts';
/**
Returns a boolean for whether the given type is a `true` or `false` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
@example
```
import type {IsBooleanLiteral} from 'type-fest';
type A = IsBooleanLiteral<true>;
//=> true
type B = IsBooleanLiteral<false>;
//=> true
type C = IsBooleanLiteral<boolean>;
//=> false
type D = IsBooleanLiteral<true | false>;
//=> false
```
@category Type Guard
@category Utilities
*/
export type IsBooleanLiteral<T> = IfNotAnyOrNever<T, {
ifNot: _IsBooleanLiteral<CollapseLiterals<UnwrapBrand<T>>>;
ifAny: false;
ifNever: false;
}>;
type _IsBooleanLiteral<T> = boolean extends T
? false
: T extends boolean
? true
: false;
export {};