@jakubmazanec/ts-utils 3.0.0-unstable.d4f095a → 3.0.0-unstable.d770f2b
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/main.js +4 -0
- package/build/main.js.map +7 -0
- package/build/types/AtLeastOneRequired.js +2 -0
- package/build/types/AtLeastOneRequired.js.map +7 -0
- package/{dist → build}/types/DeepPartial.d.ts +2 -2
- package/build/types/DeepPartial.js +2 -0
- package/build/types/DeepPartial.js.map +7 -0
- package/{dist → build}/types/DeepReadonly.d.ts +1 -1
- package/build/types/DeepReadonly.js +2 -0
- package/build/types/DeepReadonly.js.map +7 -0
- package/build/types/If.js +2 -0
- package/build/types/If.js.map +7 -0
- package/build/types/IsEqual.js +2 -0
- package/build/types/IsEqual.js.map +7 -0
- package/{dist → build}/types/LiteralUnion.d.ts +1 -1
- package/build/types/LiteralUnion.js +2 -0
- package/build/types/LiteralUnion.js.map +7 -0
- package/build/types/NonArray.js +2 -0
- package/build/types/NonArray.js.map +7 -0
- package/build/types/NonArrayLike.js +2 -0
- package/build/types/NonArrayLike.js.map +7 -0
- package/build/types/OptionalKeys.js +2 -0
- package/build/types/OptionalKeys.js.map +7 -0
- package/build/types/Parameters.js +2 -0
- package/build/types/Parameters.js.map +7 -0
- package/build/types/Primitive.js +2 -0
- package/build/types/Primitive.js.map +7 -0
- package/build/types/RequiredKeys.js +2 -0
- package/build/types/RequiredKeys.js.map +7 -0
- package/{dist → build}/types/ReturnType.d.ts +1 -1
- package/build/types/ReturnType.js +2 -0
- package/build/types/ReturnType.js.map +7 -0
- package/build/types/Simplify.js +2 -0
- package/build/types/Simplify.js.map +7 -0
- package/build/types/TupleToUnion.js +2 -0
- package/build/types/TupleToUnion.js.map +7 -0
- package/build/types/UnionToIntersection.js +2 -0
- package/build/types/UnionToIntersection.js.map +7 -0
- package/build/types/Writable.js +2 -0
- package/build/types/Writable.js.map +7 -0
- package/build/types.js +19 -0
- package/build/types.js.map +7 -0
- package/build/utils/assert.js +16 -0
- package/build/utils/assert.js.map +7 -0
- package/build/utils/is.js +5 -0
- package/build/utils/is.js.map +7 -0
- package/build/utils/isNonNullable.js +5 -0
- package/build/utils/isNonNullable.js.map +7 -0
- package/build/utils/tuple.js +5 -0
- package/build/utils/tuple.js.map +7 -0
- package/build/utils.js +6 -0
- package/build/utils.js.map +7 -0
- package/package.json +22 -11
- package/{src → source}/types/DeepPartial.ts +17 -17
- package/{src → source}/types/DeepReadonly.ts +6 -9
- package/{src → source}/types/IsEqual.ts +2 -3
- package/{src → source}/types/LiteralUnion.ts +1 -1
- package/{src → source}/types/ReturnType.ts +5 -1
- package/{src → source}/types/UnionToIntersection.ts +4 -7
- package/dist/main.js +0 -4
- package/dist/main.js.map +0 -1
- package/dist/types/AtLeastOneRequired.js +0 -35
- package/dist/types/AtLeastOneRequired.js.map +0 -1
- package/dist/types/DeepPartial.js +0 -33
- package/dist/types/DeepPartial.js.map +0 -1
- package/dist/types/DeepReadonly.js +0 -19
- package/dist/types/DeepReadonly.js.map +0 -1
- package/dist/types/If.js +0 -16
- package/dist/types/If.js.map +0 -1
- package/dist/types/IsEqual.js +0 -16
- package/dist/types/IsEqual.js.map +0 -1
- package/dist/types/LiteralUnion.js +0 -21
- package/dist/types/LiteralUnion.js.map +0 -1
- package/dist/types/NonArray.js +0 -3
- package/dist/types/NonArray.js.map +0 -1
- package/dist/types/NonArrayLike.js +0 -3
- package/dist/types/NonArrayLike.js.map +0 -1
- package/dist/types/OptionalKeys.js +0 -11
- package/dist/types/OptionalKeys.js.map +0 -1
- package/dist/types/Parameters.js +0 -18
- package/dist/types/Parameters.js.map +0 -1
- package/dist/types/Primitive.js +0 -5
- package/dist/types/Primitive.js.map +0 -1
- package/dist/types/RequiredKeys.js +0 -11
- package/dist/types/RequiredKeys.js.map +0 -1
- package/dist/types/ReturnType.js +0 -19
- package/dist/types/ReturnType.js.map +0 -1
- package/dist/types/Simplify.js +0 -7
- package/dist/types/Simplify.js.map +0 -1
- package/dist/types/TupleToUnion.js +0 -11
- package/dist/types/TupleToUnion.js.map +0 -1
- package/dist/types/UnionToIntersection.js +0 -11
- package/dist/types/UnionToIntersection.js.map +0 -1
- package/dist/types/Writable.js +0 -5
- package/dist/types/Writable.js.map +0 -1
- package/dist/types.js +0 -19
- package/dist/types.js.map +0 -1
- package/dist/utils/assert.js +0 -41
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/is.js +0 -31
- package/dist/utils/is.js.map +0 -1
- package/dist/utils/isNonNullable.js +0 -21
- package/dist/utils/isNonNullable.js.map +0 -1
- package/dist/utils/tuple.js +0 -6
- package/dist/utils/tuple.js.map +0 -1
- package/dist/utils.js +0 -6
- package/dist/utils.js.map +0 -1
- /package/{dist → build}/main.d.ts +0 -0
- /package/{dist → build}/types/AtLeastOneRequired.d.ts +0 -0
- /package/{dist → build}/types/If.d.ts +0 -0
- /package/{dist → build}/types/IsEqual.d.ts +0 -0
- /package/{dist → build}/types/NonArray.d.ts +0 -0
- /package/{dist → build}/types/NonArrayLike.d.ts +0 -0
- /package/{dist → build}/types/OptionalKeys.d.ts +0 -0
- /package/{dist → build}/types/Parameters.d.ts +0 -0
- /package/{dist → build}/types/Primitive.d.ts +0 -0
- /package/{dist → build}/types/RequiredKeys.d.ts +0 -0
- /package/{dist → build}/types/Simplify.d.ts +0 -0
- /package/{dist → build}/types/TupleToUnion.d.ts +0 -0
- /package/{dist → build}/types/UnionToIntersection.d.ts +0 -0
- /package/{dist → build}/types/Writable.d.ts +0 -0
- /package/{dist → build}/types.d.ts +0 -0
- /package/{dist → build}/utils/assert.d.ts +0 -0
- /package/{dist → build}/utils/is.d.ts +0 -0
- /package/{dist → build}/utils/isNonNullable.d.ts +0 -0
- /package/{dist → build}/utils/tuple.d.ts +0 -0
- /package/{dist → build}/utils.d.ts +0 -0
- /package/{src → source}/main.ts +0 -0
- /package/{src → source}/types/AtLeastOneRequired.ts +0 -0
- /package/{src → source}/types/If.ts +0 -0
- /package/{src → source}/types/NonArray.ts +0 -0
- /package/{src → source}/types/NonArrayLike.ts +0 -0
- /package/{src → source}/types/OptionalKeys.ts +0 -0
- /package/{src → source}/types/Parameters.ts +0 -0
- /package/{src → source}/types/Primitive.ts +0 -0
- /package/{src → source}/types/RequiredKeys.ts +0 -0
- /package/{src → source}/types/Simplify.ts +0 -0
- /package/{src → source}/types/TupleToUnion.ts +0 -0
- /package/{src → source}/types/Writable.ts +0 -0
- /package/{src → source}/types.ts +0 -0
- /package/{src → source}/utils/assert.ts +0 -0
- /package/{src → source}/utils/is.ts +0 -0
- /package/{src → source}/utils/isNonNullable.ts +0 -0
- /package/{src → source}/utils/tuple.ts +0 -0
- /package/{src → source}/utils.ts +0 -0
package/build/main.js
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Primitive } from './Primitive.js';
|
|
2
2
|
/**
|
|
3
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
4
|
*
|
|
@@ -30,7 +30,7 @@ import type { Primitive } from './Primitive.js';
|
|
|
30
30
|
*
|
|
31
31
|
* @typeParam T Base for the new type
|
|
32
32
|
*/
|
|
33
|
-
export 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;
|
|
33
|
+
export 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
34
|
/**
|
|
35
35
|
* Helper type for {@link DeepPartial}.
|
|
36
36
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Primitive } from './Primitive.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates union type by combining primitve types and literal types while allowing auto-completion in IDEs.
|
|
4
4
|
* This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @typeParam T Base for the new type
|
|
17
17
|
*/
|
|
18
|
-
export type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> = T extends (...args: any[]) => infer R ?
|
|
18
|
+
export type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> = T extends (...args: any[]) => infer R ? R extends PromiseLike<infer J> ? J : R : never;
|
package/build/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export * from "./types/AtLeastOneRequired.js";
|
|
3
|
+
export * from "./types/DeepPartial.js";
|
|
4
|
+
export * from "./types/DeepReadonly.js";
|
|
5
|
+
export * from "./types/If.js";
|
|
6
|
+
export * from "./types/IsEqual.js";
|
|
7
|
+
export * from "./types/LiteralUnion.js";
|
|
8
|
+
export * from "./types/NonArray.js";
|
|
9
|
+
export * from "./types/NonArrayLike.js";
|
|
10
|
+
export * from "./types/OptionalKeys.js";
|
|
11
|
+
export * from "./types/Parameters.js";
|
|
12
|
+
export * from "./types/Primitive.js";
|
|
13
|
+
export * from "./types/RequiredKeys.js";
|
|
14
|
+
export * from "./types/ReturnType.js";
|
|
15
|
+
export * from "./types/Simplify.js";
|
|
16
|
+
export * from "./types/TupleToUnion.js";
|
|
17
|
+
export * from "./types/UnionToIntersection.js";
|
|
18
|
+
export * from "./types/Writable.js";
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../source/types.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './types/AtLeastOneRequired.js';\nexport * from './types/DeepPartial.js';\nexport * from './types/DeepReadonly.js';\nexport * from './types/If.js';\nexport * from './types/IsEqual.js';\nexport * from './types/LiteralUnion.js';\nexport * from './types/NonArray.js';\nexport * from './types/NonArrayLike.js';\nexport * from './types/OptionalKeys.js';\nexport * from './types/Parameters.js';\nexport * from './types/Primitive.js';\nexport * from './types/RequiredKeys.js';\nexport * from './types/ReturnType.js';\nexport * from './types/Simplify.js';\nexport * from './types/TupleToUnion.js';\nexport * from './types/UnionToIntersection.js';\nexport * from './types/Writable.js';\n"],
|
|
5
|
+
"mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export class AssertionError extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* @param message Message added to the default error message
|
|
5
|
+
*/
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(`Wrong assertion encountered${message ? `: "${message}"` : ""}!`);
|
|
8
|
+
this.name = "AssertionError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function assert(condition, errorMessage) {
|
|
12
|
+
if (!condition) {
|
|
13
|
+
throw new AssertionError(errorMessage);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 /**\n * @param message Message added to the default error message\n */\n constructor(message?: string) {\n super(`Wrong assertion encountered${message ? `: \"${message}\"` : ''}!`);\n\n this.name = 'AssertionError';\n }\n}\n\n/**\n * A function that throws {@link AssertionError} (with optional message defined with `errorMessage`) if\n * `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
|
+
"mappings": ";AAGO,aAAM,uBAAuB,MAAM;AAAA;AAAA;AAAA;AAAA,EAIxC,YAAY,SAAkB;AAC5B,UAAM,8BAA8B,UAAU,MAAM,OAAO,MAAM,EAAE,GAAG;AAEtE,SAAK,OAAO;AAAA,EACd;AACF;AA0BO,gBAAS,OAAO,WAAoB,cAA0C;AAEnF,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,eAAe,YAAY;AAAA,EACvC;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/utils/is.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * A generic type guard. If `isMatched` is `true`, TypeScript assumes `value` is of type `T`.\n * You can use it to narrow types:\n *\n * ```TypeScript\n * interface Foo {\n * value: string;\n * }\n *\n * interface Bar {\n * value: number;\n * }\n *\n * declare let foobar: Foo | Bar;\n *\n * if (is<Foo>(foobar, typeof foobar.value === 'string')) {\n * // `typeof foobar` is now `Foo`\n * } else {\n * // `typeof foobar` is now `Bar`\n * }\n * ```\n *\n * @typeParam T Potential type of `value`\n * @param value Value being checked\n * @param isMatched Specifies if `value` is of type `T`\n * @return Value of `isMatched`\n */\nexport function is<T>(value: unknown, isMatched: boolean): value is T {\n return isMatched;\n}\n"],
|
|
5
|
+
"mappings": ";AA2BO,gBAAS,GAAM,OAAgB,WAAgC;AACpE,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/utils/isNonNullable.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * A type guard that checks whether variable is not `null` or `undefined`:\n *\n * ```TypeScript\n * declare let foobar: string | null;\n *\n * if (isNonNullable(foobar)) {\n * // `typeof foobar` is now `string`\n * } else {\n * // `typeof foobar` is now `null`\n * }\n * ```\n *\n * @typeParam T Type of `value`\n * @param value Value being checked\n * @return `true` if `value` is non-nullable\n */\nexport function isNonNullable<T>(value: T): value is NonNullable<T> {\n return value !== undefined && value !== null;\n}\n"],
|
|
5
|
+
"mappings": ";AAiBO,gBAAS,cAAiB,OAAmC;AAClE,SAAO,UAAU,UAAa,UAAU;AAC1C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/utils/tuple.ts"],
|
|
4
|
+
"sourcesContent": ["import {type Primitive} from '../types.js';\n\n// eslint-disable-next-line @typescript-eslint/ban-types -- this is intended\nexport function tuple<T extends Array<Primitive | {}>>(...values: T) {\n return values;\n}\n"],
|
|
5
|
+
"mappings": ";AAGO,gBAAS,SAA0C,QAAW;AACnE,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/utils.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../source/utils.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './utils/assert.js';\nexport * from './utils/is.js';\nexport * from './utils/isNonNullable.js';\nexport * from './utils/tuple.js';\n"],
|
|
5
|
+
"mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/ts-utils",
|
|
3
|
-
"version": "3.0.0-unstable.
|
|
3
|
+
"version": "3.0.0-unstable.d770f2b",
|
|
4
4
|
"description": "Collection of TypeScript types and utilities.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,23 +11,34 @@
|
|
|
11
11
|
"author": "Jakub Mazanec <jakub@mazanec.dev>",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"type": "module",
|
|
14
|
-
"exports": "./
|
|
14
|
+
"exports": "./build/main.js",
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"build",
|
|
17
|
+
"source"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
-
"clean": "del-cli coverage
|
|
22
|
-
"
|
|
23
|
-
"
|
|
20
|
+
"build": "del-cli build tsconfig.tsbuildinfo && esbuild \"source/**/*\" --platform=node --target=node20.8 --outdir=build --sourcemap && tsc",
|
|
21
|
+
"clean": "del-cli coverage build *.tsbuildinfo",
|
|
22
|
+
"develop": "concurrently \"esbuild \"source/**/*\" --platform=node --target=node20.8 --outdir=build --sourcemap --watch\" \"tsc --watch\"",
|
|
23
|
+
"document": "del-cli docs && typedoc --options typedoc.config.cjs",
|
|
24
|
+
"format": "prettier . --write --ignore-unknown",
|
|
24
25
|
"lint": "eslint .",
|
|
25
|
-
"test": "
|
|
26
|
+
"test": "del-cli coverage && vitest run --coverage --passWithNoTests",
|
|
26
27
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
30
|
+
"@types/node": "^20.8.5",
|
|
31
|
+
"@vitest/coverage-v8": "^1.2.0",
|
|
32
|
+
"concurrently": "^8.0.0",
|
|
33
|
+
"del-cli": "^5.0.0",
|
|
34
|
+
"esbuild": "^0.19.11",
|
|
35
|
+
"eslint": "^8.56.0",
|
|
36
|
+
"prettier": "^3.0.0",
|
|
37
|
+
"prettier-plugin-packagejson": "^2.4.3",
|
|
38
|
+
"typedoc": "^0.25.2",
|
|
39
|
+
"typedoc-plugin-markdown": "^3.15.1",
|
|
40
|
+
"typescript": "^5.3.3",
|
|
41
|
+
"vitest": "^1.2.0"
|
|
31
42
|
},
|
|
32
43
|
"packageManager": "npm@10.1.0",
|
|
33
44
|
"engines": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface -- needed */
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import {type Primitive} from './Primitive.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 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.
|
|
@@ -33,22 +33,22 @@ import type {Primitive} from './Primitive.js';
|
|
|
33
33
|
*
|
|
34
34
|
* @typeParam T Base for the new type
|
|
35
35
|
*/
|
|
36
|
-
export type DeepPartial<T> =
|
|
37
|
-
? T
|
|
38
|
-
: T extends Map<infer KeyType, infer ValueType>
|
|
39
|
-
|
|
40
|
-
: T extends
|
|
41
|
-
|
|
42
|
-
: T extends
|
|
43
|
-
?
|
|
44
|
-
: T extends
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
export type DeepPartial<T> =
|
|
37
|
+
T extends Date | Primitive | RegExp ? T
|
|
38
|
+
: T extends Map<infer KeyType, infer ValueType> ? DeepPartialMap<KeyType, ValueType>
|
|
39
|
+
: T extends Set<infer ItemType> ? DeepPartialSet<ItemType>
|
|
40
|
+
: T extends ReadonlyMap<infer KeyType, infer ValueType> ?
|
|
41
|
+
DeepPartialReadonlyMap<KeyType, ValueType>
|
|
42
|
+
: T extends ReadonlySet<infer ItemType> ? DeepPartialReadonlySet<ItemType>
|
|
43
|
+
: T extends (...args: any[]) => unknown ? T | undefined
|
|
44
|
+
: T extends object ?
|
|
45
|
+
T extends (
|
|
46
|
+
Array<infer I> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
47
|
+
) ?
|
|
48
|
+
I[] extends (
|
|
49
|
+
T // Test for arrays (non-tuples) specifically
|
|
50
|
+
) ?
|
|
51
|
+
Array<DeepPartial<I | undefined>> // Recreate relevant array type to prevent eager evaluation of circular reference
|
|
52
52
|
: DeepPartialObject<T> // Tuples behave properly
|
|
53
53
|
: DeepPartialObject<T>
|
|
54
54
|
: unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any -- needed */
|
|
2
2
|
|
|
3
|
-
import type
|
|
3
|
+
import {type Primitive} from './Primitive.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Same as built-in `Readonly`, but works recursively:
|
|
@@ -19,14 +19,11 @@ import type {Primitive} from './Primitive.js';
|
|
|
19
19
|
*
|
|
20
20
|
* @typeParam T Base for the new type
|
|
21
21
|
*/
|
|
22
|
-
export type DeepReadonly<T> =
|
|
23
|
-
? T
|
|
24
|
-
: T extends ReadonlyMap<infer K, infer V>
|
|
25
|
-
|
|
26
|
-
: T extends
|
|
27
|
-
? DeepReadonlySet<I>
|
|
28
|
-
: T extends object
|
|
29
|
-
? DeepReadonlyObject<T>
|
|
22
|
+
export type DeepReadonly<T> =
|
|
23
|
+
T extends Primitive | ((...args: any[]) => unknown) ? T
|
|
24
|
+
: T extends ReadonlyMap<infer K, infer V> ? DeepReadonlyMap<K, V>
|
|
25
|
+
: T extends ReadonlySet<infer I> ? DeepReadonlySet<I>
|
|
26
|
+
: T extends object ? DeepReadonlyObject<T>
|
|
30
27
|
: unknown;
|
|
31
28
|
|
|
32
29
|
/**
|
|
@@ -12,6 +12,5 @@
|
|
|
12
12
|
* @typeParam T First type to compare
|
|
13
13
|
* @typeParam U Second type to compare
|
|
14
14
|
*/
|
|
15
|
-
export type IsEqual<T, U> =
|
|
16
|
-
? true
|
|
17
|
-
: false;
|
|
15
|
+
export type IsEqual<T, U> =
|
|
16
|
+
(<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
|
|
@@ -18,4 +18,8 @@
|
|
|
18
18
|
* @typeParam T Base for the new type
|
|
19
19
|
*/
|
|
20
20
|
export type ReturnType<T extends '' | false | ((...args: any[]) => any) | null | undefined> =
|
|
21
|
-
T extends (...args: any[]) => infer R ?
|
|
21
|
+
T extends (...args: any[]) => infer R ?
|
|
22
|
+
R extends PromiseLike<infer J> ?
|
|
23
|
+
J
|
|
24
|
+
: R
|
|
25
|
+
: never;
|
|
@@ -7,15 +7,12 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @typeParam U Base for the new type
|
|
9
9
|
*/
|
|
10
|
-
export type UnionToIntersection<U> =
|
|
11
|
-
? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean
|
|
10
|
+
export type UnionToIntersection<U> =
|
|
11
|
+
boolean extends U ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean
|
|
12
12
|
: UnionToIntersectionHelper<U>;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Helper type for {@link UnionToIntersection}.
|
|
16
16
|
*/
|
|
17
|
-
type UnionToIntersectionHelper<U> =
|
|
18
|
-
k: infer I
|
|
19
|
-
) => void
|
|
20
|
-
? I
|
|
21
|
-
: never;
|
|
17
|
+
type UnionToIntersectionHelper<U> =
|
|
18
|
+
(U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
package/dist/main.js
DELETED
package/dist/main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/main.ts"],"sourcesContent":["export * from './types.js';\nexport * from './utils.js';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,aAAa"}
|