1 | import { Match } from './_Internal';
|
2 | import { Extends } from './Extends';
|
3 | import { Equals } from './Equals';
|
4 | import { Contains } from './Contains';
|
5 | /**
|
6 | * Check whether `A` is similar to `A1` or not. In other words, it is a compact
|
7 | * type that bundles [[Equals]], [[Extends]], [[Contains]], comparison types.
|
8 | * @param A to be compared
|
9 | * @param A1 to compare to
|
10 | * @param match (?=`'default'`) to change precision
|
11 | * @returns [[Boolean]]
|
12 | * @example
|
13 | * ```ts
|
14 | * import {A} from 'ts-toolbelt'
|
15 | *
|
16 | * type test0 = A.Is<'a', 'a' | 'b', 'extends->'> // True
|
17 | * type test1 = A.Is<'a' | 'b', 'a', 'extends->'> // Boolean
|
18 | *
|
19 | * type test2 = A.Is<'a', 'a' | 'b', '<-extends'> // Boolean
|
20 | * type test3 = A.Is<'a' | 'b', 'a', '<-extends'> // True
|
21 | *
|
22 | * type test4 = A.Is<'a', 'a' | 'b', 'contains->'> // True
|
23 | * type test5 = A.Is<'a' | 'b', 'a', 'contains->'> // False
|
24 | *
|
25 | * type test6 = A.Is<'a', 'a' | 'b', '<-contains'> // False
|
26 | * type test7 = A.Is<'a' | 'b', 'a', '<-contains'> // True
|
27 | *
|
28 | * type test8 = A.Is<'a', 'a' | 'b', 'equals'> // False
|
29 | * type test9 = A.Is<'b' |'a', 'a' | 'b', 'equals'> // True
|
30 | * ```
|
31 | */
|
32 | export declare type Is<A extends any, A1 extends any, match extends Match = 'default'> = {
|
33 | 'default': Extends<A, A1>;
|
34 | 'contains->': Contains<A, A1>;
|
35 | 'extends->': Extends<A, A1>;
|
36 | '<-contains': Contains<A1, A>;
|
37 | '<-extends': Extends<A1, A>;
|
38 | 'equals': Equals<A1, A>;
|
39 | }[match];
|