lay-sing 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/esm/main/array.d.ts +48 -0
- package/esm/main/array.d.ts.map +1 -0
- package/esm/main/array.js +2 -0
- package/esm/main/array.js.map +1 -0
- package/esm/main/async.d.ts +5 -0
- package/esm/main/async.d.ts.map +1 -0
- package/esm/main/async.js +2 -0
- package/esm/main/async.js.map +1 -0
- package/esm/main/boolean.d.ts +36 -0
- package/esm/main/boolean.d.ts.map +1 -0
- package/esm/main/boolean.js +2 -0
- package/esm/main/boolean.js.map +1 -0
- package/esm/main/control.d.ts +88 -0
- package/esm/main/control.d.ts.map +1 -0
- package/esm/main/control.js +2 -0
- package/esm/main/control.js.map +1 -0
- package/esm/main/doc.d.ts +30 -0
- package/esm/main/doc.d.ts.map +1 -0
- package/esm/main/doc.js +2 -0
- package/esm/main/doc.js.map +1 -0
- package/esm/main/function.d.ts +21 -0
- package/esm/main/function.d.ts.map +1 -0
- package/esm/main/function.js +3 -0
- package/esm/main/function.js.map +1 -0
- package/esm/main/index.d.ts +12 -0
- package/esm/main/index.d.ts.map +1 -0
- package/esm/main/index.js +12 -0
- package/esm/main/index.js.map +1 -0
- package/esm/main/json.d.ts +44 -0
- package/esm/main/json.d.ts.map +1 -0
- package/esm/main/json.js +2 -0
- package/esm/main/json.js.map +1 -0
- package/esm/main/key.d.ts +26 -0
- package/esm/main/key.d.ts.map +1 -0
- package/esm/main/key.js +2 -0
- package/esm/main/key.js.map +1 -0
- package/esm/main/object.d.ts +81 -0
- package/esm/main/object.d.ts.map +1 -0
- package/esm/main/object.js +2 -0
- package/esm/main/object.js.map +1 -0
- package/esm/main/type/compare.d.ts +79 -0
- package/esm/main/type/compare.d.ts.map +1 -0
- package/esm/main/type/compare.js +2 -0
- package/esm/main/type/compare.js.map +1 -0
- package/esm/main/type/index.d.ts +3 -0
- package/esm/main/type/index.d.ts.map +1 -0
- package/esm/main/type/index.js +3 -0
- package/esm/main/type/index.js.map +1 -0
- package/esm/main/type/set.d.ts +29 -0
- package/esm/main/type/set.d.ts.map +1 -0
- package/esm/main/type/set.js +2 -0
- package/esm/main/type/set.js.map +1 -0
- package/esm/main/typed-array.d.ts +5 -0
- package/esm/main/typed-array.d.ts.map +1 -0
- package/esm/main/typed-array.js +2 -0
- package/esm/main/typed-array.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/test-utils.d.ts +348 -0
- package/esm/test-utils.d.ts.map +1 -0
- package/esm/test-utils.js +49 -0
- package/esm/test-utils.js.map +1 -0
- package/package.json +29 -0
- package/script/main/array.d.ts +48 -0
- package/script/main/array.d.ts.map +1 -0
- package/script/main/array.js +3 -0
- package/script/main/array.js.map +1 -0
- package/script/main/async.d.ts +5 -0
- package/script/main/async.d.ts.map +1 -0
- package/script/main/async.js +3 -0
- package/script/main/async.js.map +1 -0
- package/script/main/boolean.d.ts +36 -0
- package/script/main/boolean.d.ts.map +1 -0
- package/script/main/boolean.js +3 -0
- package/script/main/boolean.js.map +1 -0
- package/script/main/control.d.ts +88 -0
- package/script/main/control.d.ts.map +1 -0
- package/script/main/control.js +3 -0
- package/script/main/control.js.map +1 -0
- package/script/main/doc.d.ts +30 -0
- package/script/main/doc.d.ts.map +1 -0
- package/script/main/doc.js +3 -0
- package/script/main/doc.js.map +1 -0
- package/script/main/function.d.ts +21 -0
- package/script/main/function.d.ts.map +1 -0
- package/script/main/function.js +4 -0
- package/script/main/function.js.map +1 -0
- package/script/main/index.d.ts +12 -0
- package/script/main/index.d.ts.map +1 -0
- package/script/main/index.js +28 -0
- package/script/main/index.js.map +1 -0
- package/script/main/json.d.ts +44 -0
- package/script/main/json.d.ts.map +1 -0
- package/script/main/json.js +3 -0
- package/script/main/json.js.map +1 -0
- package/script/main/key.d.ts +26 -0
- package/script/main/key.d.ts.map +1 -0
- package/script/main/key.js +3 -0
- package/script/main/key.js.map +1 -0
- package/script/main/object.d.ts +81 -0
- package/script/main/object.d.ts.map +1 -0
- package/script/main/object.js +3 -0
- package/script/main/object.js.map +1 -0
- package/script/main/type/compare.d.ts +79 -0
- package/script/main/type/compare.d.ts.map +1 -0
- package/script/main/type/compare.js +3 -0
- package/script/main/type/compare.js.map +1 -0
- package/script/main/type/index.d.ts +3 -0
- package/script/main/type/index.d.ts.map +1 -0
- package/script/main/type/index.js +19 -0
- package/script/main/type/index.js.map +1 -0
- package/script/main/type/set.d.ts +29 -0
- package/script/main/type/set.d.ts.map +1 -0
- package/script/main/type/set.js +3 -0
- package/script/main/type/set.js.map +1 -0
- package/script/main/typed-array.d.ts +5 -0
- package/script/main/typed-array.d.ts.map +1 -0
- package/script/main/typed-array.js +3 -0
- package/script/main/typed-array.js.map +1 -0
- package/script/package.json +3 -0
- package/script/test-utils.d.ts +348 -0
- package/script/test-utils.d.ts.map +1 -0
- package/script/test-utils.js +54 -0
- package/script/test-utils.js.map +1 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { KeysOfOtherType, KeysOfType } from './key.js';
|
|
2
|
+
/**
|
|
3
|
+
* Access a property `K` of object `T`, with a fallback `E` if the property doesn't exist
|
|
4
|
+
*
|
|
5
|
+
* ### Examples
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* type Result = Access<{ a: string }, 'a'> // string
|
|
9
|
+
* type Missing = Access<{ a: string }, 'x', 'default'> // 'default'
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type Access<T, K extends PropertyKey, E = never> = K extends keyof T ? T[K] : E;
|
|
13
|
+
/**
|
|
14
|
+
* Recursively makes all properties of `T` optional
|
|
15
|
+
*
|
|
16
|
+
* ### Examples
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* type Result = DeepPartial<{ a: string; nested: { b: number } }> // { a?: string; nested?: { b?: number } }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type DeepPartial<T> = {
|
|
23
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Recursively makes all properties of `T` required
|
|
27
|
+
*
|
|
28
|
+
* ### Examples
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* type Result = DeepRequire<{ a?: string; nested?: { b?: number } }>
|
|
32
|
+
* // { a: string; nested: { b: number } }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export type DeepRequire<T> = {
|
|
36
|
+
[P in keyof T]-?: T[P] extends object ? DeepRequire<T[P]> : T[P];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Returns `T` if `T` extends `A`, otherwise returns never
|
|
40
|
+
*
|
|
41
|
+
* ### Examples
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* type _1 = AssertExtends<string, string> // string
|
|
45
|
+
* type _2 = AssertExtends<string, number> // never
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export type AssertExtends<T, A> = T extends A ? T : never;
|
|
49
|
+
/**
|
|
50
|
+
* Safely picks keys `K` from type T, excluding non-existent keys
|
|
51
|
+
*
|
|
52
|
+
* ### Examples
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* type Result = SafePick<{ a: string; b: number }, 'a' | 'c'> // { a: string }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export type SafePick<T, K> = Pick<T, K & keyof T>;
|
|
59
|
+
/**
|
|
60
|
+
* Picks properties from `T` that have values of type U
|
|
61
|
+
*
|
|
62
|
+
* ### Examples
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* type A = { a: string; b: number; c: string }
|
|
66
|
+
* type Strings = PropsOfType<A, string> // { a: string; c: string }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export type PropsOfType<T, U> = Pick<T, KeysOfType<T, U>>;
|
|
70
|
+
/**
|
|
71
|
+
* Picks properties from `T` that do not have values of type U
|
|
72
|
+
*
|
|
73
|
+
* ### Examples
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* type A = { a: string; b: number; c: string }
|
|
77
|
+
* type NonStrings = PropsOfOtherType<A, string> // { b: number }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export type PropsOfOtherType<T, U> = Pick<T, KeysOfOtherType<T, U>>;
|
|
81
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/main/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE3D;;;;;;;;;GASG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEtF;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACjE,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAEzD;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAA;AAEjD;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAEzD;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/main/object.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeysOfOtherType, KeysOfType } from './key.js'\n\n/**\n * Access a property `K` of object `T`, with a fallback `E` if the property doesn't exist\n *\n * ### Examples\n *\n * ```ts\n * type Result = Access<{ a: string }, 'a'> // string\n * type Missing = Access<{ a: string }, 'x', 'default'> // 'default'\n * ```\n */\nexport type Access<T, K extends PropertyKey, E = never> = K extends keyof T ? T[K] : E\n\n/**\n * Recursively makes all properties of `T` optional\n *\n * ### Examples\n *\n * ```ts\n * type Result = DeepPartial<{ a: string; nested: { b: number } }> // { a?: string; nested?: { b?: number } }\n * ```\n */\nexport type DeepPartial<T> = {\n [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]\n}\n\n/**\n * Recursively makes all properties of `T` required\n *\n * ### Examples\n *\n * ```ts\n * type Result = DeepRequire<{ a?: string; nested?: { b?: number } }>\n * // { a: string; nested: { b: number } }\n * ```\n */\nexport type DeepRequire<T> = {\n [P in keyof T]-?: T[P] extends object ? DeepRequire<T[P]> : T[P]\n}\n\n/**\n * Returns `T` if `T` extends `A`, otherwise returns never\n *\n * ### Examples\n *\n * ```ts\n * type _1 = AssertExtends<string, string> // string\n * type _2 = AssertExtends<string, number> // never\n * ```\n */\nexport type AssertExtends<T, A> = T extends A ? T : never\n\n/**\n * Safely picks keys `K` from type T, excluding non-existent keys\n *\n * ### Examples\n *\n * ```ts\n * type Result = SafePick<{ a: string; b: number }, 'a' | 'c'> // { a: string }\n * ```\n */\nexport type SafePick<T, K> = Pick<T, K & keyof T>\n\n/**\n * Picks properties from `T` that have values of type U\n *\n * ### Examples\n *\n * ```ts\n * type A = { a: string; b: number; c: string }\n * type Strings = PropsOfType<A, string> // { a: string; c: string }\n * ```\n */\nexport type PropsOfType<T, U> = Pick<T, KeysOfType<T, U>>\n\n/**\n * Picks properties from `T` that do not have values of type U\n *\n * ### Examples\n *\n * ```ts\n * type A = { a: string; b: number; c: string }\n * type NonStrings = PropsOfOtherType<A, string> // { b: number }\n * ```\n */\nexport type PropsOfOtherType<T, U> = Pick<T, KeysOfOtherType<T, U>>\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether two types are exactly the same.
|
|
3
|
+
*
|
|
4
|
+
* This performs a structural equality comparison between `A` and `B`,
|
|
5
|
+
* rather than a one-way assignability check.
|
|
6
|
+
*
|
|
7
|
+
* ### Result
|
|
8
|
+
*
|
|
9
|
+
* - `true`: `A` and `B` are identical types
|
|
10
|
+
* - `false`: Otherwise
|
|
11
|
+
*/
|
|
12
|
+
export type Same<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether two types are different.
|
|
15
|
+
*
|
|
16
|
+
* This is the logical negation of `Same<A, B>`.
|
|
17
|
+
*
|
|
18
|
+
* ### Result
|
|
19
|
+
*
|
|
20
|
+
* - `true`: `A` and `B` are not identical
|
|
21
|
+
* - `false`: `A` and `B` are exactly the same type
|
|
22
|
+
*/
|
|
23
|
+
export type Diff<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? false : true;
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether type `A` extends type `B`.
|
|
26
|
+
*
|
|
27
|
+
* This is a non-distributive version of `extends`, ensuring
|
|
28
|
+
* the result is always a concrete boolean literal.
|
|
29
|
+
*
|
|
30
|
+
* ### Result
|
|
31
|
+
*
|
|
32
|
+
* - `true`: `A` is assignable to `B`
|
|
33
|
+
* - `false`: Otherwise
|
|
34
|
+
*
|
|
35
|
+
* **Note:** the result will never be `boolean`.
|
|
36
|
+
*/
|
|
37
|
+
export type Extends<A, B> = [A] extends [B] ? true : false;
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether type `A` is a *proper* subtype of type `B`.
|
|
40
|
+
*
|
|
41
|
+
* A proper extension means:
|
|
42
|
+
* - `A` extends `B`
|
|
43
|
+
* - `A` is not exactly the same type as `B`
|
|
44
|
+
*
|
|
45
|
+
* **Note:** the result will never be `boolean`.
|
|
46
|
+
*/
|
|
47
|
+
export type ProperExtend<A, B> = [A] extends [B] ? Same<A, B> extends false ? true : false : false;
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether two types have any overlapping members.
|
|
50
|
+
*
|
|
51
|
+
* ### Result
|
|
52
|
+
*
|
|
53
|
+
* - `true`: `A` and `B` share at least one common type
|
|
54
|
+
* - `false`: `A` and `B` are completely disjoint
|
|
55
|
+
*/
|
|
56
|
+
export type Overlap<A, B> = [A & B] extends [never] ? false : true;
|
|
57
|
+
/**
|
|
58
|
+
* Checks whether two types are disjoint.
|
|
59
|
+
*
|
|
60
|
+
* This is the logical negation of `Overlap<A, B>`.
|
|
61
|
+
*
|
|
62
|
+
* ### Result
|
|
63
|
+
*
|
|
64
|
+
* - `true`: `A` and `B` have no overlap
|
|
65
|
+
* - `false`: `A` and `B` share at least one common type
|
|
66
|
+
*/
|
|
67
|
+
export type Disjoint<A, B> = [A & B] extends [never] ? true : false;
|
|
68
|
+
/**
|
|
69
|
+
* Checks whether two types are mutually assignable.
|
|
70
|
+
*
|
|
71
|
+
* This is equivalent to checking that:
|
|
72
|
+
* - `A` extends `B`
|
|
73
|
+
* - `B` extends `A`
|
|
74
|
+
*
|
|
75
|
+
* In other words, the two types describe the same set of values,
|
|
76
|
+
* even if they are written differently.
|
|
77
|
+
*/
|
|
78
|
+
export type MutuallyAssignable<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false;
|
|
79
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/main/type/compare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAE7G;;;;;;;;;GASG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAA;AAE7G;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAE1D;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAA;AAElG;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,CAAA;AAElE;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAEnE;;;;;;;;;GASG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/main/type/compare.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Checks whether two types are exactly the same.\n *\n * This performs a structural equality comparison between `A` and `B`,\n * rather than a one-way assignability check.\n *\n * ### Result\n *\n * - `true`: `A` and `B` are identical types\n * - `false`: Otherwise\n */\nexport type Same<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false\n\n/**\n * Checks whether two types are different.\n *\n * This is the logical negation of `Same<A, B>`.\n *\n * ### Result\n *\n * - `true`: `A` and `B` are not identical\n * - `false`: `A` and `B` are exactly the same type\n */\nexport type Diff<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? false : true\n\n/**\n * Checks whether type `A` extends type `B`.\n *\n * This is a non-distributive version of `extends`, ensuring\n * the result is always a concrete boolean literal.\n *\n * ### Result\n *\n * - `true`: `A` is assignable to `B`\n * - `false`: Otherwise\n *\n * **Note:** the result will never be `boolean`.\n */\nexport type Extends<A, B> = [A] extends [B] ? true : false\n\n/**\n * Checks whether type `A` is a *proper* subtype of type `B`.\n *\n * A proper extension means:\n * - `A` extends `B`\n * - `A` is not exactly the same type as `B`\n *\n * **Note:** the result will never be `boolean`.\n */\nexport type ProperExtend<A, B> = [A] extends [B] ? Same<A, B> extends false ? true : false : false\n\n/**\n * Checks whether two types have any overlapping members.\n *\n * ### Result\n *\n * - `true`: `A` and `B` share at least one common type\n * - `false`: `A` and `B` are completely disjoint\n */\nexport type Overlap<A, B> = [A & B] extends [never] ? false : true\n\n/**\n * Checks whether two types are disjoint.\n *\n * This is the logical negation of `Overlap<A, B>`.\n *\n * ### Result\n *\n * - `true`: `A` and `B` have no overlap\n * - `false`: `A` and `B` share at least one common type\n */\nexport type Disjoint<A, B> = [A & B] extends [never] ? true : false\n\n/**\n * Checks whether two types are mutually assignable.\n *\n * This is equivalent to checking that:\n * - `A` extends `B`\n * - `B` extends `A`\n *\n * In other words, the two types describe the same set of values,\n * even if they are written differently.\n */\nexport type MutuallyAssignable<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/main/type/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./compare.js"), exports);
|
|
18
|
+
__exportStar(require("./set.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/main/type/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,2CAAwB","sourcesContent":["export * from './compare.js'\nexport * from './set.js'\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ## `IntersectOf<[A, B, ... T]>` = `A & B & ... & T`
|
|
3
|
+
*
|
|
4
|
+
* ### Examples
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* type A = { a: string, b: number };
|
|
8
|
+
* type B = { a: number, c: boolean };
|
|
9
|
+
*
|
|
10
|
+
* type Result = IntersectOf<[A, B]>;
|
|
11
|
+
* type Result = { a: never, b: number, c: boolean }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type IntersectOf<T extends readonly unknown[]> = T extends [infer F, ...infer R] ? F & IntersectOf<R> : unknown;
|
|
15
|
+
/**
|
|
16
|
+
* ## `UnionOf<[A, B, ... T]>` = `A | B | ... | T`
|
|
17
|
+
*
|
|
18
|
+
* ### Examples
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* type A = { a: string, b: number };
|
|
22
|
+
* type B = { a: number, c: boolean };
|
|
23
|
+
*
|
|
24
|
+
* type Result = UnionOf<[A, B]>;
|
|
25
|
+
* type Result = { a: string | number }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type UnionOf<T extends readonly unknown[]> = T extends [infer F, ...infer R] ? F | UnionOf<R> : never;
|
|
29
|
+
//# sourceMappingURL=set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../../src/main/type/set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAA;AAEtH;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.js","sourceRoot":"","sources":["../../../src/main/type/set.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * ## `IntersectOf<[A, B, ... T]>` = `A & B & ... & T`\n *\n * ### Examples\n *\n * ```ts\n * type A = { a: string, b: number };\n * type B = { a: number, c: boolean };\n *\n * type Result = IntersectOf<[A, B]>;\n * type Result = { a: never, b: number, c: boolean }\n * ```\n */\nexport type IntersectOf<T extends readonly unknown[]> = T extends [infer F, ...infer R] ? F & IntersectOf<R> : unknown\n\n/**\n * ## `UnionOf<[A, B, ... T]>` = `A | B | ... | T`\n *\n * ### Examples\n *\n * ```ts\n * type A = { a: string, b: number };\n * type B = { a: number, c: boolean };\n *\n * type Result = UnionOf<[A, B]>;\n * type Result = { a: string | number }\n * ```\n */\nexport type UnionOf<T extends readonly unknown[]> = T extends [infer F, ...infer R] ? F | UnionOf<R> : never\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents all possible TypedArray types
|
|
3
|
+
*/
|
|
4
|
+
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Float32Array | Float64Array | Uint32Array | BigInt64Array | BigUint64Array;
|
|
5
|
+
//# sourceMappingURL=typed-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-array.d.ts","sourceRoot":"","sources":["../../src/main/typed-array.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,UAAU,GACV,iBAAiB,GACjB,UAAU,GACV,WAAW,GACX,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,aAAa,GACb,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-array.js","sourceRoot":"","sources":["../../src/main/typed-array.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents all possible TypedArray types\n */\nexport type TypedArray =\n | Int8Array\n | Uint8Array\n | Uint8ClampedArray\n | Int16Array\n | Uint16Array\n | Int32Array\n | Float32Array\n | Float64Array\n | Uint32Array\n | BigInt64Array\n | BigUint64Array\n"]}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import type { Diff, Disjoint, Extends, If, MutuallyAssignable, Overlap, ProperExtend, SafePick, Same } from './main/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A universal no-op placeholder implemented via `Proxy`.
|
|
4
|
+
*
|
|
5
|
+
* `NOOP` can be accessed, called, or chained indefinitely without throwing.
|
|
6
|
+
* Every operation returns itself, making it safe to use as a dummy fallback
|
|
7
|
+
* for APIs, optional hooks, or unimplemented interfaces.
|
|
8
|
+
*
|
|
9
|
+
* ### Special behaviors
|
|
10
|
+
*
|
|
11
|
+
* - Callable: invoking `NOOP()` returns `NOOP`
|
|
12
|
+
* - Property access: `NOOP.anything` returns `NOOP`
|
|
13
|
+
* - Promise-safe: `NOOP.then` is `undefined`, so it is not treated as a Promise
|
|
14
|
+
* - Primitive coercion (`toString`, `valueOf`, `Symbol.toPrimitive`) yields
|
|
15
|
+
* a stable string representation: `"[NOOP]"`
|
|
16
|
+
*
|
|
17
|
+
* This is useful in scenarios where a value is required syntactically but
|
|
18
|
+
* should perform no action and never fail at runtime.
|
|
19
|
+
*
|
|
20
|
+
* ### Examples
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* NOOP.foo.bar().baz.qux; // safe, returns NOOP
|
|
24
|
+
* String(NOOP); // "[NOOP]"
|
|
25
|
+
* await NOOP; // does not await (not thenable)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const NOOP: any;
|
|
29
|
+
/**
|
|
30
|
+
* Represents the result of a type assertion based on a boolean condition.
|
|
31
|
+
* If the condition is true, the result has a `success` property; otherwise, it has a `fail` property.
|
|
32
|
+
*
|
|
33
|
+
* @template B The boolean condition result (true or false)
|
|
34
|
+
* @template R The type of the result value (default is void)
|
|
35
|
+
*/
|
|
36
|
+
type Result<B extends true | false, R = void> = B extends true ? {
|
|
37
|
+
/**
|
|
38
|
+
* ## Expect to succeed without type error
|
|
39
|
+
*/
|
|
40
|
+
success: R;
|
|
41
|
+
} : {
|
|
42
|
+
/**
|
|
43
|
+
* ## Expect to fail with type error
|
|
44
|
+
*/
|
|
45
|
+
fail: R;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Type-level testing utility that allows checking various relationships between types.
|
|
49
|
+
* Provides methods to test type equality, extension, properties, and more.
|
|
50
|
+
*
|
|
51
|
+
* @template T The type being tested
|
|
52
|
+
* @template H Hidden property keys that are already used (internal tracking)
|
|
53
|
+
*
|
|
54
|
+
* ### Examples
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* // Test if two types are identical
|
|
58
|
+
* expect<number>().toBe<number>().success
|
|
59
|
+
* expect<number>().toBe<string>().fail
|
|
60
|
+
* // Test if one type extends another
|
|
61
|
+
* expect<2>().toExtend<number>().success
|
|
62
|
+
* expect<2>().toExtend<string>().fail
|
|
63
|
+
* // Test if type has a specific property
|
|
64
|
+
* expect<{name: string}>().toHaveProperty<'name'>().success
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export type ExpectType<T, H extends PropertyKey = never> = Omit<({
|
|
68
|
+
T: T;
|
|
69
|
+
inspect: {
|
|
70
|
+
[K in keyof T]: T[K];
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Tests if the current type is exactly the same as the provided type U.
|
|
74
|
+
*
|
|
75
|
+
* @template U The type to compare with
|
|
76
|
+
*
|
|
77
|
+
* ### Examples
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* expect<any>().toBe<any>().success
|
|
81
|
+
* expect<never>().toBe<never>().success
|
|
82
|
+
* expect<false>().toBe<true>().fail
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
toBe<U>(): Result<Same<T, U>>;
|
|
86
|
+
/**
|
|
87
|
+
* Tests if the current type T extends the provided type U.
|
|
88
|
+
*
|
|
89
|
+
* @template U The type to check extension against
|
|
90
|
+
*
|
|
91
|
+
* ### Examples
|
|
92
|
+
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* expect<3.14>().toExtend<number>().success
|
|
95
|
+
* expect<2>().toExtend<string>().fail
|
|
96
|
+
* expect<'hello'>().toExtend<string>().success
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
toExtend<U>(): Result<Extends<T, U>>;
|
|
100
|
+
/**
|
|
101
|
+
* Tests if the current type T properly extends the provided type U (extends but is not the same).
|
|
102
|
+
*
|
|
103
|
+
* @template U The type to check proper extension against
|
|
104
|
+
*
|
|
105
|
+
* ### Examples
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* expect<2>().toProperExtend<number>().success
|
|
109
|
+
* expect<'a' | 'b'>().toProperExtend<string>().success
|
|
110
|
+
* expect<number>().toProperExtend<number>().fail
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
toProperExtend<U>(): Result<ProperExtend<T, U>>;
|
|
114
|
+
/**
|
|
115
|
+
* Tests if the current type T has a property with key K.
|
|
116
|
+
*
|
|
117
|
+
* @template K The property key to check for
|
|
118
|
+
*
|
|
119
|
+
* ### Examples
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* type WithProp = { prop: string; another: number }
|
|
123
|
+
* expect<WithProp>().toHaveProperty<'prop'>().success
|
|
124
|
+
* expect<WithProp>().toHaveProperty<'another'>().success
|
|
125
|
+
* expect<WithProp>().toHaveProperty<'missing'>().fail
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
toHaveProperty<K extends PropertyKey>(): Result<Extends<K, keyof T>>;
|
|
129
|
+
} & SafePick<{
|
|
130
|
+
/**
|
|
131
|
+
* Tests if the current type extends the Number primitive type.
|
|
132
|
+
* Available only if the current type extends number.
|
|
133
|
+
*
|
|
134
|
+
* ### Examples
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* expect<3.14>().toExtendNumber // Available and would succeed
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
toExtendNumber: ExpectType<T, H | 'toExtendNumber' | 'toExtend'>;
|
|
141
|
+
/**
|
|
142
|
+
* Tests if the current type extends the String primitive type.
|
|
143
|
+
* Available only if the current type extends string.
|
|
144
|
+
*
|
|
145
|
+
* ### Examples
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* expect<'hello'>().toExtendString // Available and would succeed
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
toExtendString: ExpectType<T, H | 'toExtendString' | 'toExtend'>;
|
|
152
|
+
/**
|
|
153
|
+
* Tests if the current type extends the Boolean primitive type.
|
|
154
|
+
* Available only if the current type extends boolean.
|
|
155
|
+
*
|
|
156
|
+
* ### Examples
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* expect<true>().toExtendBoolean // Available and would succeed
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
toExtendBoolean: ExpectType<T, H | 'toExtendBoolean' | 'toExtend'>;
|
|
163
|
+
}, If<Extends<T, number>, 'toExtendNumber'> | If<Extends<T, string>, 'toExtendString'> | If<Extends<T, boolean>, 'toExtendBoolean'>> & SafePick<{
|
|
164
|
+
/**
|
|
165
|
+
* Tests if the current type is exactly `any`.
|
|
166
|
+
* Available only if the current type is `any`.
|
|
167
|
+
*
|
|
168
|
+
* ### Examples
|
|
169
|
+
*
|
|
170
|
+
* ```ts
|
|
171
|
+
* expect<any>().toBeAny // Available and would succeed
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
toBeAny: ExpectType<T, H | 'toBeAny' | 'toBe'>;
|
|
175
|
+
/**
|
|
176
|
+
* Tests if the current type is exactly `never`.
|
|
177
|
+
* Available only if the current type is `never`.
|
|
178
|
+
*
|
|
179
|
+
* ### Examples
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* expect<never>().toBeNever // Available and would succeed
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
toBeNever: ExpectType<T, H | 'toBeNever' | 'toBe'>;
|
|
186
|
+
/**
|
|
187
|
+
* Tests if the current type is exactly `unknown`.
|
|
188
|
+
* Available only if the current type is `unknown`.
|
|
189
|
+
*
|
|
190
|
+
* ### Examples
|
|
191
|
+
*
|
|
192
|
+
* ```ts
|
|
193
|
+
* expect<unknown>().toBeUnknown // Available and would succeed
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
toBeUnknown: ExpectType<T, H | 'toBeUnknown' | 'toBe'>;
|
|
197
|
+
/**
|
|
198
|
+
* Tests if the current type is exactly `void`.
|
|
199
|
+
* Available only if the current type is `void`.
|
|
200
|
+
*
|
|
201
|
+
* ### Examples
|
|
202
|
+
*
|
|
203
|
+
* ```ts
|
|
204
|
+
* expect<void>().toBeVoid // Available and would succeed
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
toBeVoid: ExpectType<T, H | 'toBeVoid' | 'toBe'>;
|
|
208
|
+
/**
|
|
209
|
+
* Tests if the current type is exactly `true` (boolean literal).
|
|
210
|
+
* Available only if the current type is `true`.
|
|
211
|
+
*
|
|
212
|
+
* ### Examples
|
|
213
|
+
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* expect<true>().toBeTrue // Available and would succeed
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
toBeTrue: ExpectType<T, H | 'toBeTrue' | 'toBe' | 'toExtendBoolean'>;
|
|
219
|
+
/**
|
|
220
|
+
* Tests if the current type is exactly `false` (boolean literal).
|
|
221
|
+
* Available only if the current type is `false`.
|
|
222
|
+
*
|
|
223
|
+
* ### Examples
|
|
224
|
+
*
|
|
225
|
+
* ```ts
|
|
226
|
+
* expect<false>().toBeFalse // Available and would succeed
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
toBeFalse: ExpectType<T, H | 'toBeFalse' | 'toBe' | 'toExtendBoolean'>;
|
|
230
|
+
}, If<Same<T, any>, 'toBeAny'> | If<Same<T, never>, 'toBeNever'> | If<Same<T, unknown>, 'toBeUnknown'> | If<Same<T, void>, 'toBeVoid'> | If<Same<T, true>, 'toBeTrue'> | If<Same<T, false>, 'toBeFalse'>>), H>;
|
|
231
|
+
/**
|
|
232
|
+
* Creates an instance of ExpectType to perform type-level assertions on the given type.
|
|
233
|
+
* This function enables testing various type relationships at compile time.
|
|
234
|
+
* NOTE: This function does nothing at runtime and is purely for type-level testing.
|
|
235
|
+
*
|
|
236
|
+
* @template T The type to be tested
|
|
237
|
+
*
|
|
238
|
+
* @returns An ExpectType instance with methods to test type relationships
|
|
239
|
+
*
|
|
240
|
+
* ### Examples
|
|
241
|
+
*
|
|
242
|
+
* ```ts
|
|
243
|
+
* // Test exact type equality
|
|
244
|
+
* expect<number>().toBe<number>().success
|
|
245
|
+
* expect<number>().toBe<string>().fail
|
|
246
|
+
* // Test if one type extends another
|
|
247
|
+
* expect<3.14>().toExtend<number>().success
|
|
248
|
+
* expect<2>().toExtend<string>().fail
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
export declare function expect<T>(): ExpectType<T>;
|
|
252
|
+
export declare function expect<T>(_: T): ExpectType<T>;
|
|
253
|
+
/**
|
|
254
|
+
* Type-level utility that compares two types and provides methods to test their relationship.
|
|
255
|
+
* Offers options to check if types are same, different, overlapping, disjoint, or mutually assignable.
|
|
256
|
+
*
|
|
257
|
+
* @template T First type to compare
|
|
258
|
+
* @template U Second type to compare
|
|
259
|
+
* @template H Hidden property keys that are already used (internal tracking)
|
|
260
|
+
*
|
|
261
|
+
* ### Examples
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* // Check if two types are the same
|
|
265
|
+
* compare<number, number>().same // Available
|
|
266
|
+
* // Check if two types are different
|
|
267
|
+
* compare<number, string>().different // Available
|
|
268
|
+
* // Check if two types overlap
|
|
269
|
+
* compare<4, number>().overlap.different // Available
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export type CompareTypes<T, U, H extends PropertyKey = never> = Omit<SafePick<{
|
|
273
|
+
/**
|
|
274
|
+
* Available when types T and U are exactly the same.
|
|
275
|
+
*
|
|
276
|
+
* ### Examples
|
|
277
|
+
*
|
|
278
|
+
* ```ts
|
|
279
|
+
* compare<3, 3>().same // Available
|
|
280
|
+
* compare<boolean, boolean>().same // Available
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
same: CompareTypes<T, U, H | 'same'>;
|
|
284
|
+
/**
|
|
285
|
+
* Available when types T and U are different.
|
|
286
|
+
*
|
|
287
|
+
* ### Examples
|
|
288
|
+
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* compare<4, 'abc'>().different // Available
|
|
291
|
+
* compare<number, 4>().different // Available
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
different: CompareTypes<T, U, H | 'different'>;
|
|
295
|
+
/**
|
|
296
|
+
* Available when types T and U have some overlap.
|
|
297
|
+
*
|
|
298
|
+
* ### Examples
|
|
299
|
+
*
|
|
300
|
+
* ```ts
|
|
301
|
+
* compare<4, number>().overlap // Available since 4 overlaps with number
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
overlap: CompareTypes<T, U, H | 'overlap'>;
|
|
305
|
+
/**
|
|
306
|
+
* Available when types T and U have no overlap (are disjoint).
|
|
307
|
+
*
|
|
308
|
+
* ### Examples
|
|
309
|
+
*
|
|
310
|
+
* ```ts
|
|
311
|
+
* compare<4, 'abc'>().different.disjoint // Available since 4 and 'abc' are disjoint
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
disjoint: CompareTypes<T, U, H | 'disjoint'>;
|
|
315
|
+
/**
|
|
316
|
+
* Available when types T and U are mutually assignable (each type can be assigned to the other).
|
|
317
|
+
*
|
|
318
|
+
* ### Examples
|
|
319
|
+
*
|
|
320
|
+
* ```ts
|
|
321
|
+
* compare<1 | 2, 1 | 2>().mutuallyAssignable // Available since identical union types are mutually assignable
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
mutuallyAssignable: CompareTypes<T, U, H | 'mutuallyAssignable'>;
|
|
325
|
+
}, If<Same<T, U>, 'same'> | If<Diff<T, U>, 'different'> | If<Overlap<T, U>, 'overlap'> | If<Disjoint<T, U>, 'disjoint'> | If<MutuallyAssignable<T, U>, 'mutuallyAssignable'>>, H>;
|
|
326
|
+
/**
|
|
327
|
+
* Creates an instance of CompareTypes to perform type-level comparisons between two types.
|
|
328
|
+
* This function enables testing various relationships between types at compile time.
|
|
329
|
+
* NOTE: This function does nothing at runtime and is purely for type-level testing.
|
|
330
|
+
*
|
|
331
|
+
* @template T First type to compare
|
|
332
|
+
* @template U Second type to compare
|
|
333
|
+
*
|
|
334
|
+
* @returns A CompareTypes instance with methods to test relationships between T and U
|
|
335
|
+
*
|
|
336
|
+
* ### Examples
|
|
337
|
+
*
|
|
338
|
+
* ```ts
|
|
339
|
+
* // Compare two identical types
|
|
340
|
+
* compare<number, number>().same // Results in an available property
|
|
341
|
+
* // Compare two different but overlapping types
|
|
342
|
+
* compare<4, number>().overlap.different // Results in available properties
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
export declare function compare<T, U>(): CompareTypes<T, U>;
|
|
346
|
+
export declare function compare<T, U>(t: T, u: U): CompareTypes<T, U>;
|
|
347
|
+
export {};
|
|
348
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,EAAE,EACF,kBAAkB,EAClB,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,IAAI,EACL,MAAM,iBAAiB,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,EAAE,GAkBlB,CAAA;AAED;;;;;;GAMG;AACH,KAAK,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,IAAI,GAAG;IAC7D;;OAEG;IACH,OAAO,EAAE,CAAC,CAAA;CACX,GACC;IACA;;OAEG;IACH,IAAI,EAAE,CAAC,CAAA;CACR,CAAA;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,KAAK,IAAI,IAAI,CAC7D,CACI;IACA,CAAC,EAAE,CAAC,CAAA;IACJ,OAAO,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAAE,CAAA;IAEjC;;;;;;;;;;;;OAYG;IACH,IA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