@jakubmazanec/ts-utils 2.1.2 → 3.0.0-next.7305494
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/README.md +1 -1
- package/dist/types/DeepPartial.js +31 -1
- package/dist/types/DeepPartial.js.map +1 -1
- package/dist/types/DeepReadonly.js +17 -1
- package/dist/types/DeepReadonly.js.map +1 -1
- package/dist/types/LiteralUnion.js +19 -1
- package/dist/types/LiteralUnion.js.map +1 -1
- package/dist/types/UnionToIntersection.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */ /**
|
|
2
|
+
* 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.
|
|
3
|
+
*
|
|
4
|
+
* ```TypeScript
|
|
5
|
+
* import { DeepPartial } from '@ori/ts-utils';
|
|
6
|
+
* import { UiSettings } from './UiSettings';
|
|
7
|
+
*
|
|
8
|
+
* let settings: UiSettings = {
|
|
9
|
+
* lineNumbers: true,
|
|
10
|
+
* scrollbar: {
|
|
11
|
+
* useShadows: false,
|
|
12
|
+
* vertical: 'visible',
|
|
13
|
+
* horizontal: 'auto',
|
|
14
|
+
* },
|
|
15
|
+
* minimap: {
|
|
16
|
+
* enabled: false,
|
|
17
|
+
* },
|
|
18
|
+
* folding: {
|
|
19
|
+
* enabled: true,
|
|
20
|
+
* },
|
|
21
|
+
* };
|
|
22
|
+
*
|
|
23
|
+
* function updateSettings(newSettings: DeepPartial<UiSettings>) {
|
|
24
|
+
* return { ...settings, ...newSettings };
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* settings = updateSettings({ minimap: { enabled: true } });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @typeParam T Base for the new type
|
|
31
|
+
*/ export { };
|
|
2
32
|
|
|
3
33
|
//# sourceMappingURL=DeepPartial.js.map
|
|
@@ -1 +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 {@link DeepPartial}.\n */\ninterface DeepPartialMap<KeyType, ValueType>\n extends Map<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ninterface DeepPartialSet<T> extends Set<DeepPartial<T>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ninterface DeepPartialReadonlyMap<KeyType, ValueType>\n extends ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ninterface DeepPartialReadonlySet<T> extends ReadonlySet<DeepPartial<T>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ntype DeepPartialObject<ObjectType extends object> = {\n [KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;\n};\n"],"names":[],"mappings":"AAAA,sGAAsG,
|
|
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 {@link DeepPartial}.\n */\ninterface DeepPartialMap<KeyType, ValueType>\n extends Map<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ninterface DeepPartialSet<T> extends Set<DeepPartial<T>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ninterface DeepPartialReadonlyMap<KeyType, ValueType>\n extends ReadonlyMap<DeepPartial<KeyType>, DeepPartial<ValueType>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ninterface DeepPartialReadonlySet<T> extends ReadonlySet<DeepPartial<T>> {}\n\n/**\n * Helper type for {@link DeepPartial}.\n */\ntype DeepPartialObject<ObjectType extends object> = {\n [KeyType in keyof ObjectType]?: DeepPartial<ObjectType[KeyType]>;\n};\n"],"names":[],"mappings":"AAAA,sGAAsG,GAItG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,WAkBY"}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any -- needed */
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- needed */ /**
|
|
2
|
+
* Same as built-in `Readonly`, but works recursively:
|
|
3
|
+
*
|
|
4
|
+
* ```TypeScript
|
|
5
|
+
* import { DeepReadonly } from '@ori/ts-utils';
|
|
6
|
+
*
|
|
7
|
+
* const rawData = {
|
|
8
|
+
* foo: ['bar'],
|
|
9
|
+
* };
|
|
10
|
+
*
|
|
11
|
+
* const data: DeepReadonly<typeof rawData> = rawData;
|
|
12
|
+
*
|
|
13
|
+
* data.foo.push('bar'); // error TS2339: Property 'push' does not exist on type 'readonly string[]'
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @typeParam T Base for the new type
|
|
17
|
+
*/ export { };
|
|
2
18
|
|
|
3
19
|
//# sourceMappingURL=DeepReadonly.js.map
|
|
@@ -1 +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 {@link DeepReadonly}.\n */\ntype DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;\n\n/**\n * Helper type for {@link DeepReadonly}.\n */\ntype DeepReadonlySet<I> = ReadonlySet<DeepReadonly<I>>;\n\n/**\n * Helper type for {@link DeepReadonly}.\n */\ntype DeepReadonlyObject<O extends object> = {\n readonly [K in keyof O]: DeepReadonly<O[K]>;\n};\n"],"names":[],"mappings":"AAAA,+DAA+D,
|
|
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 {@link DeepReadonly}.\n */\ntype DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;\n\n/**\n * Helper type for {@link DeepReadonly}.\n */\ntype DeepReadonlySet<I> = ReadonlySet<DeepReadonly<I>>;\n\n/**\n * Helper type for {@link DeepReadonly}.\n */\ntype DeepReadonlyObject<O extends object> = {\n readonly [K in keyof O]: DeepReadonly<O[K]>;\n};\n"],"names":[],"mappings":"AAAA,+DAA+D,GAI/D;;;;;;;;;;;;;;;;CAgBC,GACD,WAQY"}
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates union type by combining primitve types and literal types while allowing auto-completion in IDEs.
|
|
3
|
+
* This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
|
|
4
|
+
*
|
|
5
|
+
* ```TypeScript
|
|
6
|
+
* type Animal = 'cat' | 'dog' | string;
|
|
7
|
+
*
|
|
8
|
+
* const: animal: Animal = ''; // No auto-completion here...
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* ```TypeScript
|
|
12
|
+
* type Animal = LiteralUnion<'cat' | 'dog', string>;
|
|
13
|
+
*
|
|
14
|
+
* const: animal: Animal = ''; // Auto-completion works: 'cat' and 'dog' is suggested!
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @typeParam L Union of literal types
|
|
18
|
+
* @typeParam T Primitive type
|
|
19
|
+
*/ export { };
|
|
2
20
|
|
|
3
21
|
//# sourceMappingURL=LiteralUnion.js.map
|
|
@@ -1 +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":"
|
|
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":"AAEA;;;;;;;;;;;;;;;;;;CAkBC,GACD,WAAkF"}
|
|
@@ -1 +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 {@link 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;;;;;;;;CAQC,GACD,
|
|
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 {@link 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;;;;;;;;CAQC,GACD,WAEiC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/ts-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-next.7305494",
|
|
4
4
|
"description": "Collection of TypeScript types and utilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@jest/globals": "^29.5.0"
|
|
29
|
+
"@jest/globals": "^29.5.0",
|
|
30
|
+
"@types/node": "^20.8.5"
|
|
30
31
|
},
|
|
31
|
-
"packageManager": "npm@
|
|
32
|
+
"packageManager": "npm@10.1.0",
|
|
32
33
|
"engines": {
|
|
33
|
-
"node": "
|
|
34
|
+
"node": "^20.8.0"
|
|
34
35
|
}
|
|
35
36
|
}
|