@jakubmazanec/ts-utils 1.0.0-fdb1c25

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.
Files changed (86) hide show
  1. package/LICENSE +18 -0
  2. package/dist/main.d.ts +2 -0
  3. package/dist/main.js +4 -0
  4. package/dist/main.js.map +1 -0
  5. package/dist/types/AtLeastOneRequired.d.ts +36 -0
  6. package/dist/types/AtLeastOneRequired.js +35 -0
  7. package/dist/types/AtLeastOneRequired.js.map +1 -0
  8. package/dist/types/DeepPartial.d.ts +60 -0
  9. package/dist/types/DeepPartial.js +3 -0
  10. package/dist/types/DeepPartial.js.map +1 -0
  11. package/dist/types/DeepReadonly.d.ts +34 -0
  12. package/dist/types/DeepReadonly.js +3 -0
  13. package/dist/types/DeepReadonly.js.map +1 -0
  14. package/dist/types/If.d.ts +15 -0
  15. package/dist/types/If.js +16 -0
  16. package/dist/types/If.js.map +1 -0
  17. package/dist/types/IsEqual.d.ts +26 -0
  18. package/dist/types/IsEqual.js +16 -0
  19. package/dist/types/IsEqual.js.map +1 -0
  20. package/dist/types/LiteralUnion.d.ts +21 -0
  21. package/dist/types/LiteralUnion.js +3 -0
  22. package/dist/types/LiteralUnion.js.map +1 -0
  23. package/dist/types/NonArray.d.ts +1 -0
  24. package/dist/types/NonArray.js +3 -0
  25. package/dist/types/NonArray.js.map +1 -0
  26. package/dist/types/NonArrayLike.d.ts +1 -0
  27. package/dist/types/NonArrayLike.js +3 -0
  28. package/dist/types/NonArrayLike.js.map +1 -0
  29. package/dist/types/OptionalKeys.d.ts +12 -0
  30. package/dist/types/OptionalKeys.js +11 -0
  31. package/dist/types/OptionalKeys.js.map +1 -0
  32. package/dist/types/Parameters.d.ts +17 -0
  33. package/dist/types/Parameters.js +18 -0
  34. package/dist/types/Parameters.js.map +1 -0
  35. package/dist/types/Primitive.d.ts +4 -0
  36. package/dist/types/Primitive.js +5 -0
  37. package/dist/types/Primitive.js.map +1 -0
  38. package/dist/types/RequiredKeys.d.ts +12 -0
  39. package/dist/types/RequiredKeys.js +11 -0
  40. package/dist/types/RequiredKeys.js.map +1 -0
  41. package/dist/types/ReturnType.d.ts +18 -0
  42. package/dist/types/ReturnType.js +19 -0
  43. package/dist/types/ReturnType.js.map +1 -0
  44. package/dist/types/TupleToUnion.d.ts +10 -0
  45. package/dist/types/TupleToUnion.js +11 -0
  46. package/dist/types/TupleToUnion.js.map +1 -0
  47. package/dist/types/UnionToIntersection.d.ts +15 -0
  48. package/dist/types/UnionToIntersection.js +11 -0
  49. package/dist/types/UnionToIntersection.js.map +1 -0
  50. package/dist/types.d.ts +15 -0
  51. package/dist/types.js +17 -0
  52. package/dist/types.js.map +1 -0
  53. package/dist/utils/assert.d.ts +34 -0
  54. package/dist/utils/assert.js +41 -0
  55. package/dist/utils/assert.js.map +1 -0
  56. package/dist/utils/is.d.ts +28 -0
  57. package/dist/utils/is.js +31 -0
  58. package/dist/utils/is.js.map +1 -0
  59. package/dist/utils/isNonNullable.d.ts +18 -0
  60. package/dist/utils/isNonNullable.js +21 -0
  61. package/dist/utils/isNonNullable.js.map +1 -0
  62. package/dist/utils.d.ts +3 -0
  63. package/dist/utils.js +5 -0
  64. package/dist/utils.js.map +1 -0
  65. package/package.json +35 -0
  66. package/src/main.ts +2 -0
  67. package/src/types/AtLeastOneRequired.ts +37 -0
  68. package/src/types/DeepPartial.ts +83 -0
  69. package/src/types/DeepReadonly.ts +47 -0
  70. package/src/types/If.ts +15 -0
  71. package/src/types/IsEqual.ts +29 -0
  72. package/src/types/LiteralUnion.ts +22 -0
  73. package/src/types/NonArray.ts +3 -0
  74. package/src/types/NonArrayLike.ts +3 -0
  75. package/src/types/OptionalKeys.ts +15 -0
  76. package/src/types/Parameters.ts +20 -0
  77. package/src/types/Primitive.ts +4 -0
  78. package/src/types/RequiredKeys.ts +15 -0
  79. package/src/types/ReturnType.ts +21 -0
  80. package/src/types/TupleToUnion.ts +10 -0
  81. package/src/types/UnionToIntersection.ts +21 -0
  82. package/src/types.ts +15 -0
  83. package/src/utils/assert.ts +44 -0
  84. package/src/utils/is.ts +30 -0
  85. package/src/utils/isNonNullable.ts +20 -0
  86. package/src/utils.ts +3 -0
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Jakub Mazanec
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
17
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export * from './utils.js';
package/dist/main.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./types.js";
2
+ export * from "./utils.js";
3
+
4
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/main.ts"],"sourcesContent":["export * from './types.js';\nexport * from './utils.js';\n"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Constructs new type from `T` so that at least one property from the set of properties `P` is required:
3
+ *
4
+ * ```TypeScript
5
+ * import { AtLeastOneRequired } from '@ori/ts-utils';
6
+ *
7
+ * type FooOrBar = AtLeastOneRequired<{foo: string; bar: string; qux: string}, 'foo' | 'bar'>;
8
+ *
9
+ * const fooOrBar1: FooOrBar = {
10
+ * foo: 'this is required',
11
+ * qux: 'this always required',
12
+ * };
13
+ *
14
+ * const fooOrBar2: FooOrBar = {
15
+ * bar: 'or this is required',
16
+ * qux: 'this always required',
17
+ * };
18
+ *
19
+ * const fooOrBar3: FooOrBar = {
20
+ * foo: 'we can have foo',
21
+ * bar: 'and bar',
22
+ * qux: 'this always required',
23
+ * };
24
+ *
25
+ * const fooOrBar4: FooOrBar = {
26
+ * // no foo nor bar
27
+ * qux: 'this always required',
28
+ * }; // error TS2322: Type '{ qux: string; }' is not assignable to type 'FooOrBar'
29
+ * ```
30
+ *
31
+ * @typeParam T Base for the new type
32
+ * @typeParam P String literal or union of string literals specifying properties of `T`
33
+ */
34
+ export declare type AtLeastOneRequired<T, P extends keyof T = keyof T> = {
35
+ [K in P]-?: Partial<Pick<T, Exclude<P, K>>> & Required<Pick<T, K>>;
36
+ }[P] & Pick<T, Exclude<keyof T, P>>;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Constructs new type from `T` so that at least one property from the set of properties `P` is required:
3
+ *
4
+ * ```TypeScript
5
+ * import { AtLeastOneRequired } from '@ori/ts-utils';
6
+ *
7
+ * type FooOrBar = AtLeastOneRequired<{foo: string; bar: string; qux: string}, 'foo' | 'bar'>;
8
+ *
9
+ * const fooOrBar1: FooOrBar = {
10
+ * foo: 'this is required',
11
+ * qux: 'this always required',
12
+ * };
13
+ *
14
+ * const fooOrBar2: FooOrBar = {
15
+ * bar: 'or this is required',
16
+ * qux: 'this always required',
17
+ * };
18
+ *
19
+ * const fooOrBar3: FooOrBar = {
20
+ * foo: 'we can have foo',
21
+ * bar: 'and bar',
22
+ * qux: 'this always required',
23
+ * };
24
+ *
25
+ * const fooOrBar4: FooOrBar = {
26
+ * // no foo nor bar
27
+ * qux: 'this always required',
28
+ * }; // error TS2322: Type '{ qux: string; }' is not assignable to type 'FooOrBar'
29
+ * ```
30
+ *
31
+ * @typeParam T Base for the new type
32
+ * @typeParam P String literal or union of string literals specifying properties of `T`
33
+ */ export { };
34
+
35
+ //# sourceMappingURL=AtLeastOneRequired.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/AtLeastOneRequired.ts"],"sourcesContent":["/**\n * Constructs new type from `T` so that at least one property from the set of properties `P` is required:\n *\n * ```TypeScript\n * import { AtLeastOneRequired } from '@ori/ts-utils';\n *\n * type FooOrBar = AtLeastOneRequired<{foo: string; bar: string; qux: string}, 'foo' | 'bar'>;\n *\n * const fooOrBar1: FooOrBar = {\n * foo: 'this is required',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar2: FooOrBar = {\n * bar: 'or this is required',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar3: FooOrBar = {\n * foo: 'we can have foo',\n * bar: 'and bar',\n * qux: 'this always required',\n * };\n *\n * const fooOrBar4: FooOrBar = {\n * // no foo nor bar\n * qux: 'this always required',\n * }; // error TS2322: Type '{ qux: string; }' is not assignable to type 'FooOrBar'\n * ```\n *\n * @typeParam T Base for the new type\n * @typeParam P String literal or union of string literals specifying properties of `T`\n */\nexport type AtLeastOneRequired<T, P extends keyof T = keyof T> = {\n [K in P]-?: Partial<Pick<T, Exclude<P, K>>> & Required<Pick<T, K>>;\n}[P] &\n Pick<T, Exclude<keyof T, P>>;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG,CACH,WAG+B"}
@@ -0,0 +1,60 @@
1
+ import type { Primitive } from './Primitive.js';
2
+ /**
3
+ * Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to which you need to merge another object, which would be a deep partial of a default object, or 2) you need to test or mock complex object, but most of its keys would be redundant for this purpose.
4
+ *
5
+ * ```TypeScript
6
+ * import { DeepPartial } from '@ori/ts-utils';
7
+ * import { UiSettings } from './UiSettings';
8
+ *
9
+ * let settings: UiSettings = {
10
+ * lineNumbers: true,
11
+ * scrollbar: {
12
+ * useShadows: false,
13
+ * vertical: 'visible',
14
+ * horizontal: 'auto',
15
+ * },
16
+ * minimap: {
17
+ * enabled: false,
18
+ * },
19
+ * folding: {
20
+ * enabled: true,
21
+ * },
22
+ * };
23
+ *
24
+ * function updateSettings(newSettings: DeepPartial<UiSettings>) {
25
+ * return { ...settings, ...newSettings };
26
+ * }
27
+ *
28
+ * settings = updateSettings({ minimap: { enabled: true } });
29
+ * ```
30
+ *
31
+ * @typeParam T Base for the new type
32
+ */
33
+ export declare type DeepPartial<T> = T extends Date | Primitive | RegExp ? T : T extends Map<infer KeyType, infer ValueType> ? DeepPartialMap<KeyType, ValueType> : T extends Set<infer ItemType> ? DeepPartialSet<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? DeepPartialReadonlyMap<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? DeepPartialReadonlySet<ItemType> : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends Array<infer I> ? I[] extends T ? Array<DeepPartial<I | undefined>> : DeepPartialObject<T> : DeepPartialObject<T> : unknown;
34
+ /**
35
+ * Helper type for {@linkcode DeepPartial}.
36
+ */
37
+ interface DeepPartialMap<KeyType, ValueType> extends Map<DeepPartial<KeyType>, DeepPartial<ValueType>> {
38
+ }
39
+ /**
40
+ * Helper type for {@linkcode DeepPartial}.
41
+ */
42
+ interface DeepPartialSet<T> extends Set<DeepPartial<T>> {
43
+ }
44
+ /**
45
+ * Helper type for {@linkcode DeepPartial}.
46
+ */
47
+ interface DeepPartialReadonlyMap<KeyType, ValueType> extends ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>> {
48
+ }
49
+ /**
50
+ * Helper type for {@linkcode DeepPartial}.
51
+ */
52
+ interface DeepPartialReadonlySet<T> extends ReadonlySet<DeepPartial<T>> {
53
+ }
54
+ /**
55
+ * Helper type for {@linkcode DeepPartial}.
56
+ */
57
+ declare type DeepPartialObject<ObjectType extends object> = {
58
+ [KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;
59
+ };
60
+ export {};
@@ -0,0 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */ export { };
2
+
3
+ //# sourceMappingURL=DeepPartial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/DeepPartial.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */\n\nimport type {Primitive} from './Primitive.js';\n\n/**\n * Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to which you need to merge another object, which would be a deep partial of a default object, or 2) you need to test or mock complex object, but most of its keys would be redundant for this purpose.\n *\n * ```TypeScript\n * import { DeepPartial } from '@ori/ts-utils';\n * import { UiSettings } from './UiSettings';\n *\n * let settings: UiSettings = {\n * lineNumbers: true,\n * scrollbar: {\n * useShadows: false,\n * vertical: 'visible',\n * horizontal: 'auto',\n * },\n * minimap: {\n * enabled: false,\n * },\n * folding: {\n * enabled: true,\n * },\n * };\n *\n * function updateSettings(newSettings: DeepPartial<UiSettings>) {\n * return { ...settings, ...newSettings };\n * }\n *\n * settings = updateSettings({ minimap: { enabled: true } });\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type DeepPartial<T> = T extends Date | Primitive | RegExp\n ? T\n : T extends Map<infer KeyType, infer ValueType>\n ? DeepPartialMap<KeyType, ValueType>\n : T extends Set<infer ItemType>\n ? DeepPartialSet<ItemType>\n : T extends ReadonlyMap<infer KeyType, infer ValueType>\n ? DeepPartialReadonlyMap<KeyType, ValueType>\n : T extends ReadonlySet<infer ItemType>\n ? DeepPartialReadonlySet<ItemType>\n : T extends (...args: any[]) => unknown\n ? T | undefined\n : T extends object\n ? T extends Array<infer I> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156\n ? I[] extends T // Test for arrays (non-tuples) specifically\n ? Array<DeepPartial<I | undefined>> // Recreate relevant array type to prevent eager evaluation of circular reference\n : DeepPartialObject<T> // Tuples behave properly\n : DeepPartialObject<T>\n : unknown;\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialMap<KeyType, ValueType>\n extends Map<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialSet<T> extends Set<DeepPartial<T>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialReadonlyMap<KeyType, ValueType>\n extends ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ninterface DeepPartialReadonlySet<T> extends ReadonlySet<DeepPartial<T>> {}\n\n/**\n * Helper type for {@linkcode DeepPartial}.\n */\ntype DeepPartialObject<ObjectType extends object> = {\n [KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;\n};\n"],"names":[],"mappings":"AAAA,wGAAwG,CAExG,WAgFE"}
@@ -0,0 +1,34 @@
1
+ import type { Primitive } from './Primitive.js';
2
+ /**
3
+ * Same as built-in `Readonly`, but works recursively:
4
+ *
5
+ * ```TypeScript
6
+ * import { DeepReadonly } from '@ori/ts-utils';
7
+ *
8
+ * const rawData = {
9
+ * foo: ['bar'],
10
+ * };
11
+ *
12
+ * const data: DeepReadonly<typeof rawData> = rawData;
13
+ *
14
+ * data.foo.push('bar'); // error TS2339: Property 'push' does not exist on type 'readonly string[]'
15
+ * ```
16
+ *
17
+ * @typeParam T Base for the new type
18
+ */
19
+ export declare type DeepReadonly<T> = T extends Primitive | ((...args: any[]) => unknown) ? T : T extends ReadonlyMap<infer K, infer V> ? DeepReadonlyMap<K, V> : T extends ReadonlySet<infer I> ? DeepReadonlySet<I> : T extends object ? DeepReadonlyObject<T> : unknown;
20
+ /**
21
+ * Helper type for {@linkcode DeepReadonly}.
22
+ */
23
+ declare type DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;
24
+ /**
25
+ * Helper type for {@linkcode DeepReadonly}.
26
+ */
27
+ declare type DeepReadonlySet<I> = ReadonlySet<DeepReadonly<I>>;
28
+ /**
29
+ * Helper type for {@linkcode DeepReadonly}.
30
+ */
31
+ declare type DeepReadonlyObject<O extends object> = {
32
+ readonly [K in keyof O]: DeepReadonly<O[K]>;
33
+ };
34
+ export {};
@@ -0,0 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any -- needed */ export { };
2
+
3
+ //# sourceMappingURL=DeepReadonly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/DeepReadonly.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nimport type {Primitive} from './Primitive.js';\n\n/**\n * Same as built-in `Readonly`, but works recursively:\n *\n * ```TypeScript\n * import { DeepReadonly } from '@ori/ts-utils';\n *\n * const rawData = {\n * foo: ['bar'],\n * };\n *\n * const data: DeepReadonly<typeof rawData> = rawData;\n *\n * data.foo.push('bar'); // error TS2339: Property 'push' does not exist on type 'readonly string[]'\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type DeepReadonly<T> = T extends Primitive | ((...args: any[]) => unknown)\n ? T\n : T extends ReadonlyMap<infer K, infer V>\n ? DeepReadonlyMap<K, V>\n : T extends ReadonlySet<infer I>\n ? DeepReadonlySet<I>\n : T extends object\n ? DeepReadonlyObject<T>\n : unknown;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlySet<I> = ReadonlySet<DeepReadonly<I>>;\n\n/**\n * Helper type for {@linkcode DeepReadonly}.\n */\ntype DeepReadonlyObject<O extends object> = {\n readonly [K in keyof O]: DeepReadonly<O[K]>;\n};\n"],"names":[],"mappings":"AAAA,iEAAiE,CAEjE,WA4CE"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `If<X, Y, T, F>` is shorthand for conditional type `X extends Y ? T : F`:
3
+ *
4
+ * ```TypeScript
5
+ * // these two types are equivalent:
6
+ * type NonNullable<T> = T extends null | undefined ? never : T;
7
+ * type NonNullable<T> = If<T, null | undefined, never, T>;
8
+ * ```
9
+ *
10
+ * @typeParam X Type on the left of the `extends`
11
+ * @typeParam Y Type on the right of the `extends`
12
+ * @typeParam T Type returned when `X` is assignable to `Y`
13
+ * @typeParam F Type returned when `X` isn't assignable to `Y`
14
+ */
15
+ export declare type If<X, Y, T, F> = X extends Y ? T : F;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `If<X, Y, T, F>` is shorthand for conditional type `X extends Y ? T : F`:
3
+ *
4
+ * ```TypeScript
5
+ * // these two types are equivalent:
6
+ * type NonNullable<T> = T extends null | undefined ? never : T;
7
+ * type NonNullable<T> = If<T, null | undefined, never, T>;
8
+ * ```
9
+ *
10
+ * @typeParam X Type on the left of the `extends`
11
+ * @typeParam Y Type on the right of the `extends`
12
+ * @typeParam T Type returned when `X` is assignable to `Y`
13
+ * @typeParam F Type returned when `X` isn't assignable to `Y`
14
+ */ export { };
15
+
16
+ //# sourceMappingURL=If.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/If.ts"],"sourcesContent":["/**\n * `If<X, Y, T, F>` is shorthand for conditional type `X extends Y ? T : F`:\n *\n * ```TypeScript\n * // these two types are equivalent:\n * type NonNullable<T> = T extends null | undefined ? never : T;\n * type NonNullable<T> = If<T, null | undefined, never, T>;\n * ```\n *\n * @typeParam X Type on the left of the `extends`\n * @typeParam Y Type on the right of the `extends`\n * @typeParam T Type returned when `X` is assignable to `Y`\n * @typeParam F Type returned when `X` isn't assignable to `Y`\n */\nexport type If<X, Y, T, F> = X extends Y ? T : F;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG,CACH,WAAiD"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Allows you to test if two types are the same:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = IsEqual<string, number> // `typeof Result` is `false`
6
+ * ```
7
+ *
8
+ * ```TypeScript
9
+ * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
10
+ * ```
11
+ *
12
+ * @typeParam A1 First type to compare
13
+ * @typeParam A2 Second type to compare
14
+ */
15
+ export declare type IsEqual<A1, A2> = IsStrictlyEqual<Unite<A1>, Unite<A2>>;
16
+ /**
17
+ * Helper type for {@linkcode IsEqual}.
18
+ */
19
+ declare type IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
20
+ /**
21
+ * Helper type for {@linkcode IsEqual}.
22
+ */
23
+ declare type Unite<T> = T extends Record<string, unknown> ? {
24
+ [K in keyof T]: T[K];
25
+ } : T;
26
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Allows you to test if two types are the same:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = IsEqual<string, number> // `typeof Result` is `false`
6
+ * ```
7
+ *
8
+ * ```TypeScript
9
+ * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`
10
+ * ```
11
+ *
12
+ * @typeParam A1 First type to compare
13
+ * @typeParam A2 Second type to compare
14
+ */ export { };
15
+
16
+ //# sourceMappingURL=IsEqual.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/IsEqual.ts"],"sourcesContent":["/**\n * Allows you to test if two types are the same:\n *\n * ```TypeScript\n * type Result = IsEqual<string, number> // `typeof Result` is `false`\n * ```\n *\n * ```TypeScript\n * type Result = IsEqual<{foo: string}, {foo: string}> // `typeof Result` is `true`\n * ```\n *\n * @typeParam A1 First type to compare\n * @typeParam A2 Second type to compare\n */\nexport type IsEqual<A1, A2> = IsStrictlyEqual<Unite<A1>, Unite<A2>>;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype IsStrictlyEqual<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1\n ? true\n : false\n ? true\n : false;\n\n/**\n * Helper type for {@linkcode IsEqual}.\n */\ntype Unite<T> = T extends Record<string, unknown> ? {[K in keyof T]: T[K]} : T;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG,CACH,WAc+E"}
@@ -0,0 +1,21 @@
1
+ import type { Primitive } from './Primitive.js';
2
+ /**
3
+ * Creates union type by combining primitve types and literal types while allowing auto-completion in IDEs.
4
+ * This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
5
+ *
6
+ * ```TypeScript
7
+ * type Animal = 'cat' | 'dog' | string;
8
+ *
9
+ * const: animal: Animal = ''; // No auto-completion here...
10
+ * ```
11
+ *
12
+ * ```TypeScript
13
+ * type Animal = LiteralUnion<'cat' | 'dog', string>;
14
+ *
15
+ * const: animal: Animal = ''; // Auto-completion works: 'cat' and 'dog' is suggested!
16
+ * ```
17
+ *
18
+ * @typeParam L Union of literal types
19
+ * @typeParam T Primitive type
20
+ */
21
+ export declare type LiteralUnion<L, T extends Primitive> = L | (Record<never, never> & T);
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=LiteralUnion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/LiteralUnion.ts"],"sourcesContent":["import type {Primitive} from './Primitive.js';\n\n/**\n * Creates union type by combining primitve types and literal types while allowing auto-completion in IDEs.\n * This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).\n *\n * ```TypeScript\n * type Animal = 'cat' | 'dog' | string;\n *\n * const: animal: Animal = ''; // No auto-completion here...\n * ```\n *\n * ```TypeScript\n * type Animal = LiteralUnion<'cat' | 'dog', string>;\n *\n * const: animal: Animal = ''; // Auto-completion works: 'cat' and 'dog' is suggested!\n * ```\n *\n * @typeParam L Union of literal types\n * @typeParam T Primitive type\n */\nexport type LiteralUnion<L, T extends Primitive> = L | (Record<never, never> & T);\n"],"names":[],"mappings":"AAAA,WAqBkF"}
@@ -0,0 +1 @@
1
+ export declare type NonArray<T> = T extends any[] ? never : T;
@@ -0,0 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any -- needed */ export { };
2
+
3
+ //# sourceMappingURL=NonArray.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/NonArray.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nexport type NonArray<T> = T extends any[] ? never : T;\n"],"names":[],"mappings":"AAAA,iEAAiE,CAEjE,WAAsD"}
@@ -0,0 +1 @@
1
+ export declare type NonArrayLike<T> = T extends ArrayLike<any> ? never : T;
@@ -0,0 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any -- needed */ export { };
2
+
3
+ //# sourceMappingURL=NonArrayLike.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/NonArrayLike.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\nexport type NonArrayLike<T> = T extends ArrayLike<any> ? never : T;\n"],"names":[],"mappings":"AAAA,iEAAiE,CAEjE,WAAmE"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Extracts the optional keys of type `T`:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = OptionalKeys<{ foo?: number; bar?: string; baz: boolean; }>; // `typeof Result` is `'foo' | 'bar`
6
+ * ```
7
+ *
8
+ * @typeParam T Base for the new type
9
+ */
10
+ export declare type OptionalKeys<T extends object> = Exclude<{
11
+ [K in keyof T]: T extends Record<K, T[K]> ? never : K;
12
+ }[keyof T], undefined>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Extracts the optional keys of type `T`:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = OptionalKeys<{ foo?: number; bar?: string; baz: boolean; }>; // `typeof Result` is `'foo' | 'bar`
6
+ * ```
7
+ *
8
+ * @typeParam T Base for the new type
9
+ */ export { };
10
+
11
+ //# sourceMappingURL=OptionalKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/OptionalKeys.ts"],"sourcesContent":["/**\n * Extracts the optional keys of type `T`:\n *\n * ```TypeScript\n * type Result = OptionalKeys<{ foo?: number; bar?: string; baz: boolean; }>; // `typeof Result` is `'foo' | 'bar`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type OptionalKeys<T extends object> = Exclude<\n {\n [K in keyof T]: T extends Record<K, T[K]> ? never : K;\n }[keyof T],\n undefined\n>;\n"],"names":[],"mappings":"AAAA;;;;;;;;GAQG,CACH,WAKE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Constructs a tuple type from the types used in the parameters of a function type `T`.
3
+ * Similarly like built-in `Parameters` utility type, but works also on nullable and other types.
4
+ *
5
+ * ```TypeScript
6
+ * interface Foo {
7
+ * get?: (id: number) => string;
8
+ * }
9
+ *
10
+ * declare const foo: Foo;
11
+ *
12
+ * type Result = Parameters<typeof foo.get>; // `typeof Result` is `[id: number]`
13
+ * ```
14
+ *
15
+ * @typeParam T Base for the new type
16
+ */
17
+ export declare type Parameters<T extends '' | false | ((...args: any[]) => any) | null | undefined> = T extends (...args: infer P) => any ? P : never;
@@ -0,0 +1,18 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any -- needed */ /**
2
+ * Constructs a tuple type from the types used in the parameters of a function type `T`.
3
+ * Similarly like built-in `Parameters` utility type, but works also on nullable and other types.
4
+ *
5
+ * ```TypeScript
6
+ * interface Foo {
7
+ * get?: (id: number) => string;
8
+ * }
9
+ *
10
+ * declare const foo: Foo;
11
+ *
12
+ * type Result = Parameters<typeof foo.get>; // `typeof Result` is `[id: number]`
13
+ * ```
14
+ *
15
+ * @typeParam T Base for the new type
16
+ */ export { };
17
+
18
+ //# sourceMappingURL=Parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/Parameters.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\n/**\n * Constructs a tuple type from the types used in the parameters of a function type `T`.\n * Similarly like built-in `Parameters` utility type, but works also on nullable and other types.\n *\n * ```TypeScript\n * interface Foo {\n * get?: (id: number) => string;\n * }\n *\n * declare const foo: Foo;\n *\n * type Result = Parameters<typeof foo.get>; // `typeof Result` is `[id: number]`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type Parameters<T extends '' | false | ((...args: any[]) => any) | null | undefined> =\n T extends (...args: infer P) => any ? P : never;\n"],"names":[],"mappings":"AAAA,iEAAiE,CAEjE;;;;;;;;;;;;;;;GAeG,CACH,WACkD"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Union of primitive types.
3
+ */
4
+ export declare type Primitive = bigint | boolean | number | string | symbol | null | undefined;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Union of primitive types.
3
+ */ export { };
4
+
5
+ //# sourceMappingURL=Primitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/Primitive.ts"],"sourcesContent":["/**\n * Union of primitive types.\n */\nexport type Primitive = bigint | boolean | number | string | symbol | null | undefined;\n"],"names":[],"mappings":"AAAA;;GAEG,CACH,WAAuF"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Extracts the non-optional keys of type `T`:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = RequiredKeys<{ foo: number; bar: string; baz?: boolean; }>; // `typeof Result` is `'foo' | 'bar`
6
+ * ```
7
+ *
8
+ * @typeParam T Base for the new type
9
+ */
10
+ export declare type RequiredKeys<T extends object> = Exclude<{
11
+ [K in keyof T]: T extends Record<K, T[K]> ? K : never;
12
+ }[keyof T], undefined>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Extracts the non-optional keys of type `T`:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = RequiredKeys<{ foo: number; bar: string; baz?: boolean; }>; // `typeof Result` is `'foo' | 'bar`
6
+ * ```
7
+ *
8
+ * @typeParam T Base for the new type
9
+ */ export { };
10
+
11
+ //# sourceMappingURL=RequiredKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/RequiredKeys.ts"],"sourcesContent":["/**\n * Extracts the non-optional keys of type `T`:\n *\n * ```TypeScript\n * type Result = RequiredKeys<{ foo: number; bar: string; baz?: boolean; }>; // `typeof Result` is `'foo' | 'bar`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type RequiredKeys<T extends object> = Exclude<\n {\n [K in keyof T]: T extends Record<K, T[K]> ? K : never;\n }[keyof T],\n undefined\n>;\n"],"names":[],"mappings":"AAAA;;;;;;;;GAQG,CACH,WAKE"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Constructs a type consisting of the return type of function `T`.
3
+ * Similarly like built-in `ReturnType` utility type, but works also on nullable and other types,
4
+ * and if you use it with async function, it doesn't return the type as a `Promise`:
5
+ *
6
+ * ```TypeScript
7
+ * interface Foo {
8
+ * get?: (id: number) => Promise<string>;
9
+ * }
10
+ *
11
+ * declare const foo: Foo;
12
+ *
13
+ * type Result = ReturnType<typeof foo.get>; // `typeof Result` is `string`
14
+ * ```
15
+ *
16
+ * @typeParam T Base for the new type
17
+ */
18
+ export declare type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> = T extends (...args: any[]) => infer R ? (R extends PromiseLike<infer J> ? J : R) : never;
@@ -0,0 +1,19 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any -- needed */ /**
2
+ * Constructs a type consisting of the return type of function `T`.
3
+ * Similarly like built-in `ReturnType` utility type, but works also on nullable and other types,
4
+ * and if you use it with async function, it doesn't return the type as a `Promise`:
5
+ *
6
+ * ```TypeScript
7
+ * interface Foo {
8
+ * get?: (id: number) => Promise<string>;
9
+ * }
10
+ *
11
+ * declare const foo: Foo;
12
+ *
13
+ * type Result = ReturnType<typeof foo.get>; // `typeof Result` is `string`
14
+ * ```
15
+ *
16
+ * @typeParam T Base for the new type
17
+ */ export { };
18
+
19
+ //# sourceMappingURL=ReturnType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/ReturnType.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\n\n/**\n * Constructs a type consisting of the return type of function `T`.\n * Similarly like built-in `ReturnType` utility type, but works also on nullable and other types,\n * and if you use it with async function, it doesn't return the type as a `Promise`:\n *\n * ```TypeScript\n * interface Foo {\n * get?: (id: number) => Promise<string>;\n * }\n *\n * declare const foo: Foo;\n *\n * type Result = ReturnType<typeof foo.get>; // `typeof Result` is `string`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> =\n T extends (...args: any[]) => infer R ? (R extends PromiseLike<infer J> ? J : R) : never;\n"],"names":[],"mappings":"AAAA,iEAAiE,CAEjE;;;;;;;;;;;;;;;;GAgBG,CACH,WAC2F"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Converts tuple type to union type:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `"foo" | "bar"`
6
+ * ```
7
+ *
8
+ * @typeParam T Base for the new type
9
+ */
10
+ export declare type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Converts tuple type to union type:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `"foo" | "bar"`
6
+ * ```
7
+ *
8
+ * @typeParam T Base for the new type
9
+ */ export { };
10
+
11
+ //# sourceMappingURL=TupleToUnion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/TupleToUnion.ts"],"sourcesContent":["/**\n * Converts tuple type to union type:\n *\n * ```TypeScript\n * type Result = TupleToUnion<['foo', 'bar']>; // `typeof Result` is `\"foo\" | \"bar\"`\n * ```\n *\n * @typeParam T Base for the new type\n */\nexport type TupleToUnion<T extends unknown[] | readonly unknown[]> = T[number];\n"],"names":[],"mappings":"AAAA;;;;;;;;GAQG,CACH,WAA+E"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Converts union type to intersection type:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = UnionToIntersection<{ foo: string } | { bar: string }>; // `typeof Result` is `{foo: string} & {bar: string}`
6
+ * ```
7
+ *
8
+ * @typeParam U Base for the new type
9
+ */
10
+ export declare type UnionToIntersection<U> = boolean extends U ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean : UnionToIntersectionHelper<U>;
11
+ /**
12
+ * Helper type for {@linkcode UnionToIntersection}.
13
+ */
14
+ declare type UnionToIntersectionHelper<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
15
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Converts union type to intersection type:
3
+ *
4
+ * ```TypeScript
5
+ * type Result = UnionToIntersection<{ foo: string } | { bar: string }>; // `typeof Result` is `{foo: string} & {bar: string}`
6
+ * ```
7
+ *
8
+ * @typeParam U Base for the new type
9
+ */ export { };
10
+
11
+ //# sourceMappingURL=UnionToIntersection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/UnionToIntersection.ts"],"sourcesContent":["/**\n * Converts union type to intersection type:\n *\n * ```TypeScript\n * type Result = UnionToIntersection<{ foo: string } | { bar: string }>; // `typeof Result` is `{foo: string} & {bar: string}`\n * ```\n *\n * @typeParam U Base for the new type\n */\nexport type UnionToIntersection<U> = boolean extends U\n ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean\n : UnionToIntersectionHelper<U>;\n\n/**\n * Helper type for {@linkcode UnionToIntersection}.\n */\ntype UnionToIntersectionHelper<U> = (U extends unknown ? (k: U) => void : never) extends (\n k: infer I,\n) => void\n ? I\n : never;\n"],"names":[],"mappings":"AAAA;;;;;;;;GAQG,CACH,WAWU"}
@@ -0,0 +1,15 @@
1
+ export * from './types/AtLeastOneRequired.js';
2
+ export * from './types/DeepPartial.js';
3
+ export * from './types/DeepReadonly.js';
4
+ export * from './types/If.js';
5
+ export * from './types/IsEqual.js';
6
+ export * from './types/LiteralUnion.js';
7
+ export * from './types/NonArray.js';
8
+ export * from './types/NonArrayLike.js';
9
+ export * from './types/OptionalKeys.js';
10
+ export * from './types/Parameters.js';
11
+ export * from './types/Primitive.js';
12
+ export * from './types/RequiredKeys.js';
13
+ export * from './types/ReturnType.js';
14
+ export * from './types/TupleToUnion.js';
15
+ export * from './types/UnionToIntersection.js';