main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
958 bytes
|
Line | |
---|
1 | import { And } from '../Boolean/And';
|
---|
2 | import { Or } from '../Boolean/Or';
|
---|
3 | import { Extends } from '../Any/Extends';
|
---|
4 | /**
|
---|
5 | * @hidden
|
---|
6 | */
|
---|
7 | export declare type IsStringLiteral<A extends any> = A extends string ? string extends A ? 0 : 1 : 0;
|
---|
8 | /**
|
---|
9 | * @hidden
|
---|
10 | */
|
---|
11 | export declare type IsNumberLiteral<A extends any> = A extends number ? number extends A ? 0 : 1 : 0;
|
---|
12 | /**
|
---|
13 | * Literal to restrict against
|
---|
14 | */
|
---|
15 | export declare type Kind = string | number;
|
---|
16 | /**
|
---|
17 | * Determine whether `A` is literal or not
|
---|
18 | * @param A to be checked
|
---|
19 | * @param kind (?=`'string' | 'number'`) to restrict
|
---|
20 | * @example
|
---|
21 | * ```ts
|
---|
22 | * import {A} from 'ts-toolbelt'
|
---|
23 | *
|
---|
24 | * type test0 = A.IsLiteral<1 | 2> // 1
|
---|
25 | * type test1 = A.IsLiteral<1 | 2, string> // 0
|
---|
26 | * type test2 = A.IsLiteral<1 | '2', string> // 0 | 1
|
---|
27 | * type test3 = A.IsLiteral<number> // 0
|
---|
28 | * ```
|
---|
29 | */
|
---|
30 | export declare type IsLiteral<A extends any, kind extends Kind = Kind> = And<Or<IsStringLiteral<A>, IsNumberLiteral<A>>, Extends<A, kind>>;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.