@jakubmazanec/ts-utils 3.0.19 → 3.0.20-unstable.72f063e3
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/build/types/AtLeastOneRequired.d.ts +2 -1
- package/build/types/DeepPartial.d.ts +4 -1
- package/build/types/LiteralUnion.d.ts +3 -2
- package/build/types/Simplify.d.ts +2 -1
- package/build/types/Writable.d.ts +2 -1
- package/build/utils/assert.d.ts +2 -2
- package/build/utils/assert.js.map +1 -1
- package/package.json +2 -2
- package/source/types/AtLeastOneRequired.ts +2 -1
- package/source/types/DeepPartial.ts +4 -1
- package/source/types/LiteralUnion.ts +3 -2
- package/source/types/Simplify.ts +2 -1
- package/source/types/Writable.ts +2 -1
- package/source/utils/assert.ts +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Constructs new type from `T` so that at least one property from the set of properties `P` is
|
|
2
|
+
* Constructs new type from `T` so that at least one property from the set of properties `P` is
|
|
3
|
+
* required:
|
|
3
4
|
*
|
|
4
5
|
* ```TypeScript
|
|
5
6
|
* import { AtLeastOneRequired } from '@ori/ts-utils';
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type Primitive } from './Primitive.js';
|
|
2
2
|
/**
|
|
3
|
-
* Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to
|
|
3
|
+
* Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to
|
|
4
|
+
* which you need to merge another object, which would be a deep partial of a default object, or 2)
|
|
5
|
+
* you need to test or mock complex object, but most of its keys would be redundant for this
|
|
6
|
+
* purpose.
|
|
4
7
|
*
|
|
5
8
|
* ```TypeScript
|
|
6
9
|
* import { DeepPartial } from '@ori/ts-utils';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Primitive } from './Primitive.js';
|
|
2
2
|
/**
|
|
3
|
-
* Creates union type by combining primitve types and literal types while allowing auto-completion
|
|
4
|
-
* This type is a workaround for
|
|
3
|
+
* Creates union type by combining primitve types and literal types while allowing auto-completion
|
|
4
|
+
* in IDEs. This type is a workaround for
|
|
5
|
+
* [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
|
|
5
6
|
*
|
|
6
7
|
* ```TypeScript
|
|
7
8
|
* type Animal = 'cat' | 'dog' | string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or
|
|
2
|
+
* Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or
|
|
3
|
+
* showing better hints from the language server.
|
|
3
4
|
*
|
|
4
5
|
* @typeParam T Base for the new type.
|
|
5
6
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Create a new type that removes `readonly` from object types's keys. Inverse of {@link
|
|
2
|
+
* Create a new type that removes `readonly` from object types's keys. Inverse of {@link
|
|
3
|
+
* Readonly<T>}.
|
|
3
4
|
*/
|
|
4
5
|
export type Writable<T> = {
|
|
5
6
|
-readonly [K in keyof T]: T[K];
|
package/build/utils/assert.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare class AssertionError extends Error {
|
|
|
9
9
|
constructor(message?: string);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* A function that throws {@link AssertionError} (with optional message defined with
|
|
13
|
-
* `condition` is falsy.
|
|
12
|
+
* A function that throws {@link AssertionError} (with optional message defined with
|
|
13
|
+
* `errorMessage`) if `condition` is falsy.
|
|
14
14
|
* You can use it to narrow types:
|
|
15
15
|
*
|
|
16
16
|
* ```TypeScript
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/utils/assert.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * A subclass of `Error` that indicates an assertion failure.\n */\nexport class AssertionError extends Error {\n override name = 'AssertionError';\n\n /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n }\n}\n\n/**\n * A function that throws {@link AssertionError} (with optional message defined with `errorMessage`) if
|
|
4
|
+
"sourcesContent": ["/**\n * A subclass of `Error` that indicates an assertion failure.\n */\nexport class AssertionError extends Error {\n override name = 'AssertionError';\n\n /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n }\n}\n\n/**\n * A function that throws {@link AssertionError} (with optional message defined with\n * `errorMessage`) if `condition` is falsy.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * kind: 'Foo';\n * }\n *\n * interface Bar {\n * kind: 'Bar';\n * }\n *\n * declare const foobar: Foo | Bar;\n *\n * assert(is<Foo>(foobar, foobar.kind === 'Foo'));\n *\n * // `typeof foobar` is now `Foo`\n * ```\n *\n * @param condition Condition we're asserting isn't falsy\n * @param errorMessage Message for the `AssertionError`\n */\nexport function assert(condition: unknown, errorMessage?: string): asserts condition {\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we don't mind here\n if (!condition) {\n throw new AssertionError(errorMessage);\n }\n}\n"],
|
|
5
5
|
"mappings": "AAGO,aAAM,uBAAuB,MAAM;AAAA,EAC/B,OAAO;AAAA;AAAA;AAAA;AAAA,EAKhB,YAAY,SAAkB;AAC5B,UAAM,8BAA8B,UAAU,MAAM,OAAO,MAAM,EAAE,GAAG;AAAA,EACxE;AACF;AA0BO,gBAAS,OAAO,WAAoB,cAA0C;AAEnF,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,eAAe,YAAY;AAAA,EACvC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/ts-utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.20-unstable.72f063e3",
|
|
4
4
|
"description": "Collection of TypeScript types and utilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@jakubmazanec/eslint-config": "
|
|
30
|
+
"@jakubmazanec/eslint-config": "6.0.0-unstable.72f063e3",
|
|
31
31
|
"@types/lodash": "^4.17.24",
|
|
32
32
|
"@types/node": "^24.0.4",
|
|
33
33
|
"@vitest/coverage-v8": "^4.1.10",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Constructs new type from `T` so that at least one property from the set of properties `P` is
|
|
2
|
+
* Constructs new type from `T` so that at least one property from the set of properties `P` is
|
|
3
|
+
* required:
|
|
3
4
|
*
|
|
4
5
|
* ```TypeScript
|
|
5
6
|
* import { AtLeastOneRequired } from '@ori/ts-utils';
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import {type Primitive} from './Primitive.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to
|
|
6
|
+
* Same as built-in `Partial`, but works recursively. Useful when 1) you have a config object to
|
|
7
|
+
* which you need to merge another object, which would be a deep partial of a default object, or 2)
|
|
8
|
+
* you need to test or mock complex object, but most of its keys would be redundant for this
|
|
9
|
+
* purpose.
|
|
7
10
|
*
|
|
8
11
|
* ```TypeScript
|
|
9
12
|
* import { DeepPartial } from '@ori/ts-utils';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {type Primitive} from './Primitive.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Creates union type by combining primitve types and literal types while allowing auto-completion
|
|
5
|
-
* This type is a workaround for
|
|
4
|
+
* Creates union type by combining primitve types and literal types while allowing auto-completion
|
|
5
|
+
* in IDEs. This type is a workaround for
|
|
6
|
+
* [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
|
|
6
7
|
*
|
|
7
8
|
* ```TypeScript
|
|
8
9
|
* type Animal = 'cat' | 'dog' | string;
|
package/source/types/Simplify.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or
|
|
2
|
+
* Maps all keys of type `T` to a new object type. Useful for converting interfaces to types or
|
|
3
|
+
* showing better hints from the language server.
|
|
3
4
|
*
|
|
4
5
|
* @typeParam T Base for the new type.
|
|
5
6
|
*/
|
package/source/types/Writable.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Create a new type that removes `readonly` from object types's keys. Inverse of {@link
|
|
2
|
+
* Create a new type that removes `readonly` from object types's keys. Inverse of {@link
|
|
3
|
+
* Readonly<T>}.
|
|
3
4
|
*/
|
|
4
5
|
export type Writable<T> = {
|
|
5
6
|
-readonly [K in keyof T]: T[K];
|
package/source/utils/assert.ts
CHANGED
|
@@ -13,8 +13,8 @@ export class AssertionError extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* A function that throws {@link AssertionError} (with optional message defined with
|
|
17
|
-
* `condition` is falsy.
|
|
16
|
+
* A function that throws {@link AssertionError} (with optional message defined with
|
|
17
|
+
* `errorMessage`) if `condition` is falsy.
|
|
18
18
|
* You can use it to narrow types:
|
|
19
19
|
*
|
|
20
20
|
* ```TypeScript
|