-
-
Notifications
You must be signed in to change notification settings - Fork 724
Expand file tree
/
Copy pathis-numeric-literal.d.ts
More file actions
50 lines (38 loc) · 1.04 KB
/
Copy pathis-numeric-literal.d.ts
File metadata and controls
50 lines (38 loc) · 1.04 KB
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
41
42
43
44
45
46
47
48
49
50
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 `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
@example
```
import type {IsNumericLiteral} from 'type-fest';
type A = IsNumericLiteral<0>;
//=> true
type B = IsNumericLiteral<number>;
//=> false
type C = IsNumericLiteral<100n>;
//=> true
type D = IsNumericLiteral<bigint>;
//=> false
type E = IsNumericLiteral<1 | 2 | 10n | 20n>;
//=> true
type F = IsNumericLiteral<number | bigint>;
//=> false
type G = IsNumericLiteral<1 | bigint>;
//=> boolean
```
@category Type Guard
@category Utilities
*/
export type IsNumericLiteral<T> = IfNotAnyOrNever<T, {
ifNot: _IsNumericLiteral<CollapseLiterals<UnwrapBrand<T>>>;
ifAny: false;
ifNever: false;
}>;
type _IsNumericLiteral<T> = T extends number | bigint
? number extends T
? false
: bigint extends T
? false
: true
: false;
export {};