UNPKG

958 BTypeScriptView Raw
1import { And } from '../Boolean/And';
2import { Or } from '../Boolean/Or';
3import { Extends } from '../Any/Extends';
4/**
5 * @hidden
6 */
7export declare type IsStringLiteral<A extends any> = A extends string ? string extends A ? 0 : 1 : 0;
8/**
9 * @hidden
10 */
11export declare type IsNumberLiteral<A extends any> = A extends number ? number extends A ? 0 : 1 : 0;
12/**
13 * Literal to restrict against
14 */
15export 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 */
30export declare type IsLiteral<A extends any, kind extends Kind = Kind> = And<Or<IsStringLiteral<A>, IsNumberLiteral<A>>, Extends<A, kind>>;