type-plus 7.0.0 → 7.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/README.md +4 -34
- package/cjs/any/any_type.d.ts +17 -7
- package/cjs/any/any_type.d.ts.map +1 -1
- package/cjs/array/array.some.d.ts +6 -2
- package/cjs/array/array.some.d.ts.map +1 -1
- package/cjs/array/array_plus.split_at.d.ts +6 -1
- package/cjs/array/array_plus.split_at.d.ts.map +1 -1
- package/cjs/array/reduce_while.js.map +1 -1
- package/cjs/assertion/assert_type.d.ts +3 -3
- package/cjs/assertion/assert_type.d.ts.map +1 -1
- package/cjs/assertion/assert_type.js +6 -3
- package/cjs/assertion/assert_type.js.map +1 -1
- package/cjs/bigint/bigint_type.d.ts +1 -1
- package/cjs/bigint/bigint_type.d.ts.map +1 -1
- package/cjs/bigint/strict_bigint_type.d.ts +1 -1
- package/cjs/bigint/strict_bigint_type.d.ts.map +1 -1
- package/cjs/binary/index.js +2 -25
- package/cjs/binary/index.js.map +1 -1
- package/cjs/boolean/boolean_type.d.ts +1 -1
- package/cjs/boolean/boolean_type.d.ts.map +1 -1
- package/cjs/boolean/false_type.d.ts +1 -1
- package/cjs/boolean/false_type.d.ts.map +1 -1
- package/cjs/boolean/strict_boolean_type.d.ts +1 -1
- package/cjs/boolean/strict_boolean_type.d.ts.map +1 -1
- package/cjs/boolean/true_type.d.ts +1 -1
- package/cjs/boolean/true_type.d.ts.map +1 -1
- package/cjs/equal/equal.d.ts +18 -18
- package/cjs/function/function_type.d.ts +1 -1
- package/cjs/function/function_type.d.ts.map +1 -1
- package/cjs/function/strict_function_type.d.ts +1 -1
- package/cjs/function/strict_function_type.d.ts.map +1 -1
- package/cjs/functional/context.js.map +1 -1
- package/cjs/index.d.ts +2 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +7 -22
- package/cjs/index.js.map +1 -1
- package/cjs/math/numeric_struct.d.ts +11 -0
- package/cjs/math/numeric_struct.d.ts.map +1 -1
- package/cjs/mix_types/any_or_never_type.d.ts +29 -0
- package/cjs/mix_types/any_or_never_type.d.ts.map +1 -0
- package/cjs/{any/any_or_never.js → mix_types/any_or_never_type.js} +1 -1
- package/cjs/mix_types/any_or_never_type.js.map +1 -0
- package/cjs/number/number_type.d.ts +1 -1
- package/cjs/number/number_type.d.ts.map +1 -1
- package/cjs/numeric/integer.d.ts +1 -1
- package/cjs/numeric/integer.d.ts.map +1 -1
- package/cjs/numeric/numeric_type.d.ts +1 -1
- package/cjs/numeric/numeric_type.d.ts.map +1 -1
- package/cjs/object/ANotB.d.ts +3 -2
- package/cjs/object/ANotB.d.ts.map +1 -1
- package/cjs/object/Required.d.ts +1 -1
- package/cjs/object/Required.d.ts.map +1 -1
- package/cjs/object/findKey.d.ts +1 -1
- package/cjs/object/findKey.d.ts.map +1 -1
- package/cjs/object/forEachKey.d.ts +1 -1
- package/cjs/object/forEachKey.d.ts.map +1 -1
- package/cjs/object/hasProperty.d.ts +1 -1
- package/cjs/object/hasProperty.d.ts.map +1 -1
- package/cjs/object/object_type.d.ts +1 -1
- package/cjs/object/object_type.d.ts.map +1 -1
- package/cjs/object/split.d.ts +1 -1
- package/cjs/object/split.d.ts.map +1 -1
- package/cjs/package.json +3 -1
- package/cjs/primitive.d.ts +3 -0
- package/cjs/primitive.d.ts.map +1 -1
- package/cjs/string/string_type.d.ts +1 -1
- package/cjs/string/string_type.d.ts.map +1 -1
- package/cjs/symbol/symbol_type.d.ts +1 -1
- package/cjs/symbol/symbol_type.d.ts.map +1 -1
- package/cjs/testing/stub.d.ts +3 -0
- package/cjs/testing/stub.d.ts.map +1 -1
- package/cjs/testing/stub.js.map +1 -1
- package/cjs/type/failed.d.ts +1 -1
- package/cjs/type/failed.d.ts.map +1 -1
- package/cjs/type/no_infer.d.ts +9 -6
- package/cjs/type/no_infer.d.ts.map +1 -1
- package/cjs/type-guard/is_type.d.ts +1 -1
- package/cjs/type-guard/is_type.js +1 -1
- package/cjs/type-guard/is_type.js.map +1 -1
- package/cjs/unpartial.d.ts +2 -0
- package/cjs/unpartial.d.ts.map +1 -0
- package/cjs/unpartial.js +8 -0
- package/cjs/unpartial.js.map +1 -0
- package/cjs/void/void_type.d.ts +1 -1
- package/cjs/void/void_type.d.ts.map +1 -1
- package/esm/any/any_type.d.ts +17 -7
- package/esm/any/any_type.d.ts.map +1 -1
- package/esm/array/array.some.d.ts +6 -2
- package/esm/array/array.some.d.ts.map +1 -1
- package/esm/array/array_plus.split_at.d.ts +6 -1
- package/esm/array/array_plus.split_at.d.ts.map +1 -1
- package/esm/array/reduce_while.js.map +1 -1
- package/esm/assertion/assert_type.d.ts +3 -3
- package/esm/assertion/assert_type.d.ts.map +1 -1
- package/esm/assertion/assert_type.js +7 -3
- package/esm/assertion/assert_type.js.map +1 -1
- package/esm/bigint/bigint_type.d.ts +1 -1
- package/esm/bigint/bigint_type.d.ts.map +1 -1
- package/esm/bigint/strict_bigint_type.d.ts +1 -1
- package/esm/bigint/strict_bigint_type.d.ts.map +1 -1
- package/esm/boolean/boolean_type.d.ts +1 -1
- package/esm/boolean/boolean_type.d.ts.map +1 -1
- package/esm/boolean/false_type.d.ts +1 -1
- package/esm/boolean/false_type.d.ts.map +1 -1
- package/esm/boolean/strict_boolean_type.d.ts +1 -1
- package/esm/boolean/strict_boolean_type.d.ts.map +1 -1
- package/esm/boolean/true_type.d.ts +1 -1
- package/esm/boolean/true_type.d.ts.map +1 -1
- package/esm/equal/equal.d.ts +18 -18
- package/esm/function/function_type.d.ts +1 -1
- package/esm/function/function_type.d.ts.map +1 -1
- package/esm/function/strict_function_type.d.ts +1 -1
- package/esm/function/strict_function_type.d.ts.map +1 -1
- package/esm/functional/context.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/math/numeric_struct.d.ts +11 -0
- package/esm/math/numeric_struct.d.ts.map +1 -1
- package/esm/mix_types/any_or_never_type.d.ts +29 -0
- package/esm/mix_types/any_or_never_type.d.ts.map +1 -0
- package/esm/mix_types/any_or_never_type.js +2 -0
- package/esm/mix_types/any_or_never_type.js.map +1 -0
- package/esm/number/number_type.d.ts +1 -1
- package/esm/number/number_type.d.ts.map +1 -1
- package/esm/numeric/integer.d.ts +1 -1
- package/esm/numeric/integer.d.ts.map +1 -1
- package/esm/numeric/numeric_type.d.ts +1 -1
- package/esm/numeric/numeric_type.d.ts.map +1 -1
- package/esm/object/ANotB.d.ts +3 -2
- package/esm/object/ANotB.d.ts.map +1 -1
- package/esm/object/Required.d.ts +1 -1
- package/esm/object/Required.d.ts.map +1 -1
- package/esm/object/findKey.d.ts +1 -1
- package/esm/object/findKey.d.ts.map +1 -1
- package/esm/object/forEachKey.d.ts +1 -1
- package/esm/object/forEachKey.d.ts.map +1 -1
- package/esm/object/hasProperty.d.ts +1 -1
- package/esm/object/hasProperty.d.ts.map +1 -1
- package/esm/object/object_type.d.ts +1 -1
- package/esm/object/object_type.d.ts.map +1 -1
- package/esm/object/split.d.ts +1 -1
- package/esm/object/split.d.ts.map +1 -1
- package/esm/primitive.d.ts +3 -0
- package/esm/primitive.d.ts.map +1 -1
- package/esm/string/string_type.d.ts +1 -1
- package/esm/string/string_type.d.ts.map +1 -1
- package/esm/symbol/symbol_type.d.ts +1 -1
- package/esm/symbol/symbol_type.d.ts.map +1 -1
- package/esm/testing/stub.d.ts +3 -0
- package/esm/testing/stub.d.ts.map +1 -1
- package/esm/testing/stub.js.map +1 -1
- package/esm/type/failed.d.ts +1 -1
- package/esm/type/failed.d.ts.map +1 -1
- package/esm/type/no_infer.d.ts +9 -6
- package/esm/type/no_infer.d.ts.map +1 -1
- package/esm/type-guard/is_type.d.ts +1 -1
- package/esm/type-guard/is_type.js +1 -1
- package/esm/type-guard/is_type.js.map +1 -1
- package/esm/unpartial.d.ts +2 -0
- package/esm/unpartial.d.ts.map +1 -0
- package/esm/unpartial.js +2 -0
- package/esm/unpartial.js.map +1 -0
- package/esm/void/void_type.d.ts +1 -1
- package/esm/void/void_type.d.ts.map +1 -1
- package/package.json +17 -28
- package/ts/any/any_type.ts +17 -7
- package/ts/array/array.some.ts +18 -4
- package/ts/array/array_plus.split_at.ts +1 -3
- package/ts/array/reduce_while.ts +1 -1
- package/ts/assertion/assert_type.ts +7 -4
- package/ts/bigint/bigint_type.ts +1 -1
- package/ts/bigint/strict_bigint_type.ts +1 -1
- package/ts/boolean/boolean_type.ts +1 -1
- package/ts/boolean/false_type.ts +1 -1
- package/ts/boolean/strict_boolean_type.ts +1 -1
- package/ts/boolean/true_type.ts +1 -1
- package/ts/equal/equal.ts +18 -18
- package/ts/function/function_type.ts +1 -1
- package/ts/function/strict_function_type.ts +1 -1
- package/ts/functional/context.ts +1 -1
- package/ts/index.ts +3 -2
- package/ts/math/numeric_struct.ts +0 -2
- package/ts/mix_types/any_or_never_type.ts +30 -0
- package/ts/number/number_type.ts +1 -1
- package/ts/numeric/integer.ts +1 -1
- package/ts/numeric/numeric_type.ts +1 -1
- package/ts/object/ANotB.ts +2 -1
- package/ts/object/Required.ts +1 -1
- package/ts/object/findKey.ts +1 -1
- package/ts/object/forEachKey.ts +1 -1
- package/ts/object/hasProperty.ts +1 -1
- package/ts/object/object_type.ts +1 -1
- package/ts/object/split.ts +1 -1
- package/ts/primitive.ts +3 -0
- package/ts/string/string_type.ts +1 -1
- package/ts/symbol/symbol_type.ts +1 -1
- package/ts/testing/stub.ts +3 -0
- package/ts/type/failed.ts +1 -1
- package/ts/type/no_infer.ts +9 -6
- package/ts/type-guard/is_type.ts +2 -2
- package/ts/unpartial.ts +1 -0
- package/ts/void/void_type.ts +1 -1
- package/cjs/any/any_or_never.d.ts +0 -15
- package/cjs/any/any_or_never.d.ts.map +0 -1
- package/cjs/any/any_or_never.js.map +0 -1
- package/esm/any/any_or_never.d.ts +0 -15
- package/esm/any/any_or_never.d.ts.map +0 -1
- package/esm/any/any_or_never.js +0 -2
- package/esm/any/any_or_never.js.map +0 -1
- package/ts/any/any_or_never.ts +0 -15
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-plus",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Provides additional types for TypeScript.",
|
|
5
|
-
"homepage": "https://github.com/unional/type-plus",
|
|
5
|
+
"homepage": "https://github.com/unional/type-plus/tree/main/type-plus",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/unional/type-plus/issues"
|
|
8
8
|
},
|
|
@@ -18,8 +18,14 @@
|
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"type": "module",
|
|
20
20
|
"exports": {
|
|
21
|
-
"import":
|
|
22
|
-
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./esm/index.d.ts",
|
|
23
|
+
"default": "./esm/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./cjs/index.d.ts",
|
|
27
|
+
"default": "./cjs/index.js"
|
|
28
|
+
}
|
|
23
29
|
},
|
|
24
30
|
"main": "./cjs/index.js",
|
|
25
31
|
"module": "./esm/index.js",
|
|
@@ -30,67 +36,50 @@
|
|
|
30
36
|
"ts",
|
|
31
37
|
"!ts/types",
|
|
32
38
|
"!ts/type-checker",
|
|
33
|
-
"!**/*.{spec,test,unit,accept,integrate,system}.*"
|
|
39
|
+
"!**/*.{spec,test,unit,accept,integrate,system,perf,stress}.*"
|
|
34
40
|
],
|
|
35
41
|
"dependencies": {
|
|
36
42
|
"tersify": "^3.11.1",
|
|
37
43
|
"unpartial": "^1.0.4"
|
|
38
44
|
},
|
|
39
45
|
"devDependencies": {
|
|
40
|
-
"@changesets/cli": "^2.25.2",
|
|
41
|
-
"@commitlint/cli": "^17.0.2",
|
|
42
|
-
"@commitlint/config-conventional": "^17.0.2",
|
|
43
46
|
"@jest/globals": "^29.5.0",
|
|
44
47
|
"@repobuddy/jest": "^3.4.0",
|
|
48
|
+
"@repobuddy/typescript": "^1.2.0",
|
|
45
49
|
"@size-limit/esbuild-why": "^8.2.4",
|
|
46
50
|
"@size-limit/preset-small-lib": "^8.2.4",
|
|
47
51
|
"@types/node": "^18.0.0",
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
49
|
-
"@typescript-eslint/parser": "^5.48.0",
|
|
50
52
|
"@unional/fixture": "^3.0.0",
|
|
51
53
|
"assertron": "^11.0.1",
|
|
52
54
|
"cross-env": "^7.0.3",
|
|
53
55
|
"depcheck": "^1.4.3",
|
|
54
|
-
"eslint": "^8.17.0",
|
|
55
|
-
"eslint-config-prettier": "^8.7.0",
|
|
56
|
-
"eslint-plugin-harmony": "^7.1.2",
|
|
57
|
-
"husky": "^8.0.1",
|
|
58
56
|
"jest": "^29.5.0",
|
|
59
57
|
"jest-watch-suspend": "^1.1.2",
|
|
60
58
|
"jest-watch-toggle-config-2": "^2.1.0",
|
|
61
59
|
"jest-watch-typeahead": "^2.2.2",
|
|
62
|
-
"ncp": "^2.0.0",
|
|
63
60
|
"npm-run-all": "^4.1.5",
|
|
64
|
-
"
|
|
61
|
+
"repobuddy": "^1.0.2",
|
|
65
62
|
"rimraf": "^5.0.0",
|
|
66
63
|
"satisfier": "^5.2.2",
|
|
67
64
|
"size-limit": "^8.2.4",
|
|
68
65
|
"ts-jest": "^29.1.0",
|
|
69
66
|
"tslib": "^2.4.0",
|
|
70
|
-
"
|
|
71
|
-
"typedoc-plugin-extras": "^2.3.2",
|
|
72
|
-
"typescript": "^5.0.2"
|
|
67
|
+
"typescript": "^5.0.4"
|
|
73
68
|
},
|
|
74
|
-
"packageManager": "pnpm@8.5.0",
|
|
75
69
|
"scripts": {
|
|
76
70
|
"build": "run-p build:cjs build:esm build:tslib",
|
|
77
|
-
"build:cjs": "
|
|
71
|
+
"build:cjs": "buddy ts build cjs",
|
|
78
72
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
79
|
-
"build:tslib": "
|
|
80
|
-
"
|
|
81
|
-
"clean": "rimraf cjs coverage esm lib libm tslib",
|
|
73
|
+
"build:tslib": "buddy ts build tslib",
|
|
74
|
+
"clean": "rimraf cjs coverage esm lib libm tslib --glob *.tsbuildinfo",
|
|
82
75
|
"coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --coverage",
|
|
83
|
-
"cs": "changeset",
|
|
84
76
|
"depcheck": "depcheck",
|
|
85
77
|
"lint": "eslint --ext=ts,js .",
|
|
86
78
|
"nuke": "pnpm clean && rimraf node_modules",
|
|
87
|
-
"_postinstall": "husky install",
|
|
88
|
-
"release": "changeset publish",
|
|
89
79
|
"size": "size-limit",
|
|
90
80
|
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest",
|
|
91
81
|
"test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch",
|
|
92
82
|
"verify": "npm-run-all clean -p build depcheck lint coverage -p size",
|
|
93
|
-
"version": "changeset version",
|
|
94
83
|
"watch": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch",
|
|
95
84
|
"w": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --watch"
|
|
96
85
|
}
|
package/ts/any/any_type.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Parse `T` to ensure it is exactly `any`.
|
|
4
4
|
*
|
|
5
|
+
* 🐾 *parse*
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
5
8
|
* ```ts
|
|
6
9
|
* type R = AnyType<any> // any
|
|
7
10
|
*
|
|
@@ -13,8 +16,11 @@
|
|
|
13
16
|
export type AnyType<T, Then = T, Else = never> = 0 extends 1 & T ? Then : Else
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
|
-
*
|
|
19
|
+
* Validate if `T` is exactly `any`.
|
|
20
|
+
*
|
|
21
|
+
* 🎭 *validate*
|
|
17
22
|
*
|
|
23
|
+
* @example
|
|
18
24
|
* ```ts
|
|
19
25
|
* type R = IsAny<any> // true
|
|
20
26
|
*
|
|
@@ -26,11 +32,12 @@ export type AnyType<T, Then = T, Else = never> = 0 extends 1 & T ? Then : Else
|
|
|
26
32
|
export type IsAny<T, Then = true, Else = false> = AnyType<T, Then, Else>
|
|
27
33
|
|
|
28
34
|
/**
|
|
29
|
-
*
|
|
35
|
+
* Parse `T` to ensure it is not exactly `any`.
|
|
30
36
|
*
|
|
31
|
-
*
|
|
32
|
-
* import type { NotAnyType } from 'type-plus'
|
|
37
|
+
* 🐾 *parse*
|
|
33
38
|
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
34
41
|
* type R = NotAnyType<any> // never
|
|
35
42
|
*
|
|
36
43
|
* type R = NotAnyType<never> // never
|
|
@@ -41,9 +48,12 @@ export type IsAny<T, Then = true, Else = false> = AnyType<T, Then, Else>
|
|
|
41
48
|
export type NotAnyType<T, Then = T, Else = never> = AnyType<T, Else, Then>
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
|
-
*
|
|
51
|
+
* Validate if `T` is not exactly `any`.
|
|
45
52
|
*
|
|
46
|
-
*
|
|
53
|
+
* 🎭 *validate*
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
47
57
|
* import type { IsNotAny } from 'type-plus'
|
|
48
58
|
*
|
|
49
59
|
* type R = IsNotAny<any> // false
|
package/ts/array/array.some.ts
CHANGED
|
@@ -11,6 +11,8 @@ import type { UnionOfValues } from './union_of_values.js'
|
|
|
11
11
|
*
|
|
12
12
|
* You can also change it to `strict` mode.
|
|
13
13
|
*
|
|
14
|
+
* 🔧 *utilities*
|
|
15
|
+
*
|
|
14
16
|
* @example
|
|
15
17
|
* ```ts
|
|
16
18
|
* Some<string[], string> // true
|
|
@@ -30,11 +32,16 @@ export type Some<
|
|
|
30
32
|
|
|
31
33
|
export namespace Some {
|
|
32
34
|
export type Strict<A extends unknown[], Criteria, Then, Else> = number extends A['length']
|
|
33
|
-
?
|
|
34
|
-
? Then
|
|
35
|
-
: Else
|
|
35
|
+
? StrictArray<A, Criteria, Then, Else>
|
|
36
36
|
: StrictTuple<A, Criteria, Then, Else>
|
|
37
37
|
|
|
38
|
+
export type StrictArray<A extends unknown[], Criteria, Then, Else> = IsEqual<
|
|
39
|
+
UnionOfValues<A>,
|
|
40
|
+
Criteria,
|
|
41
|
+
Then,
|
|
42
|
+
Else
|
|
43
|
+
>
|
|
44
|
+
|
|
38
45
|
export type StrictTuple<A extends unknown[], Criteria, Then, Else> = A['length'] extends 0
|
|
39
46
|
? Else
|
|
40
47
|
: IsEqual<A[0], Criteria> extends true
|
|
@@ -42,9 +49,16 @@ export namespace Some {
|
|
|
42
49
|
: StrictTuple<Tail<A>, Criteria, Then, Else>
|
|
43
50
|
|
|
44
51
|
export type Loose<A extends unknown[], Criteria, Then, Else> = number extends A['length']
|
|
45
|
-
?
|
|
52
|
+
? LooseArray<A, Criteria, Then, Else>
|
|
46
53
|
: LooseTuple<A, Criteria, Then, Else>
|
|
47
54
|
|
|
55
|
+
export type LooseArray<A extends unknown[], Criteria, Then, Else> = CanAssign<
|
|
56
|
+
UnionOfValues<A>,
|
|
57
|
+
Criteria,
|
|
58
|
+
Then,
|
|
59
|
+
Else
|
|
60
|
+
>
|
|
61
|
+
|
|
48
62
|
export type LooseTuple<A extends unknown[], Criteria, Then, Else> = A['length'] extends 0
|
|
49
63
|
? Else
|
|
50
64
|
: A[0] extends Criteria
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IndexAt } from './array_index.js'
|
|
2
|
-
import { ArrayType } from './array_type.js'
|
|
2
|
+
import type { ArrayType } from './array_type.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Splits an array into two at the specified `Index`.
|
|
@@ -33,8 +33,6 @@ export type SplitAt<A extends unknown[], Index extends number> = ArrayType<
|
|
|
33
33
|
/**
|
|
34
34
|
* Splits an array into two at the specified `Index`.
|
|
35
35
|
* The device does not work on negative index nor out of bound index.
|
|
36
|
-
*
|
|
37
|
-
* @internal
|
|
38
36
|
*/
|
|
39
37
|
export type ArraySplitAtDevice<
|
|
40
38
|
A extends unknown[],
|
package/ts/array/reduce_while.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tersify } from 'tersify'
|
|
2
2
|
import { isConstructor, type AnyConstructor } from '../class/index.js'
|
|
3
|
-
import { AnyFunction } from '../function/any_function.js'
|
|
3
|
+
import { type AnyFunction } from '../function/any_function.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* assert the subject satisfies the specified type T
|
|
@@ -82,7 +82,10 @@ assertType.noFunction = function <S>(subject: Exclude<S, AnyFunction>): void {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* 💀 deprecated. It does not work in all cases.
|
|
86
|
+
*
|
|
87
|
+
* It passes for function that can be called with `new`.
|
|
88
|
+
* If the subject is an arrow function, it can still return true after compilation.
|
|
86
89
|
*/
|
|
87
90
|
assertType.isConstructor = function (subject: AnyConstructor): asserts subject is AnyConstructor {
|
|
88
91
|
if (!isConstructor(subject)) throw TypeError(`subject is not a constructor`)
|
|
@@ -95,7 +98,7 @@ assertType.noError = function <S>(subject: Exclude<S, Error>): void {
|
|
|
95
98
|
if (subject instanceof Error) throw TypeError(`subject is an Error`)
|
|
96
99
|
}
|
|
97
100
|
|
|
98
|
-
assertType.isNever = function (
|
|
101
|
+
assertType.isNever = function (_subject: never): asserts _subject is never {}
|
|
99
102
|
|
|
100
103
|
/**
|
|
101
104
|
* creates a custom assertion function with standard TypeError.
|
|
@@ -110,4 +113,4 @@ assertType.custom = function <T>(validator: (s: T) => boolean): (subject: unknow
|
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
assertType.as = function <T>(
|
|
116
|
+
assertType.as = function <T>(_subject: unknown): asserts _subject is T {}
|
package/ts/bigint/bigint_type.ts
CHANGED
package/ts/boolean/false_type.ts
CHANGED
package/ts/boolean/true_type.ts
CHANGED
package/ts/equal/equal.ts
CHANGED
|
@@ -26,16 +26,16 @@ type IdentityEqual<A, B, Then, Else> = (<_>() => _ extends (A & _) | _ ? 1 : 2)
|
|
|
26
26
|
* Checks `A` and `B` are equal.
|
|
27
27
|
*
|
|
28
28
|
* ```ts
|
|
29
|
-
* type R =
|
|
30
|
-
* type R =
|
|
31
|
-
* type R =
|
|
32
|
-
* type R =
|
|
33
|
-
* type R =
|
|
29
|
+
* type R = IsEqual<1, 1> // true
|
|
30
|
+
* type R = IsEqual<any, any> // true
|
|
31
|
+
* type R = IsEqual<boolean, boolean> // true
|
|
32
|
+
* type R = IsEqual<true, true> // true
|
|
33
|
+
* type R = IsEqual<[1], [1]> // true
|
|
34
34
|
*
|
|
35
|
-
* type R =
|
|
36
|
-
* type R =
|
|
37
|
-
* type R =
|
|
38
|
-
* type R =
|
|
35
|
+
* type R = IsEqual<boolean, true> // false
|
|
36
|
+
* type R = IsEqual<any, 1> // false
|
|
37
|
+
* type R = IsEqual<[any], [1]> // false
|
|
38
|
+
* type R = IsEqual<{ a: 1 }, { a: 1; b: 2 }> // false
|
|
39
39
|
* ```
|
|
40
40
|
*
|
|
41
41
|
* Note that intersection type checks only works at first level.
|
|
@@ -81,16 +81,16 @@ export type IsEqual<A, B, Then = true, Else = false> = [A, B] extends [B, A]
|
|
|
81
81
|
* Checks `A` and `B` are not equal.
|
|
82
82
|
*
|
|
83
83
|
* ```ts
|
|
84
|
-
* type R =
|
|
85
|
-
* type R =
|
|
86
|
-
* type R =
|
|
87
|
-
* type R =
|
|
88
|
-
* type R =
|
|
84
|
+
* type R = IsNotEqual<1, 1> // false
|
|
85
|
+
* type R = IsNotEqual<any, any> // false
|
|
86
|
+
* type R = IsNotEqual<boolean, boolean> // false
|
|
87
|
+
* type R = IsNotEqual<true, true> // false
|
|
88
|
+
* type R = IsNotEqual<[1], [1]> // false
|
|
89
89
|
*
|
|
90
|
-
* type R =
|
|
91
|
-
* type R =
|
|
92
|
-
* type R =
|
|
93
|
-
* type R =
|
|
90
|
+
* type R = IsNotEqual<boolean, true> // true
|
|
91
|
+
* type R = IsNotEqual<any, 1> // true
|
|
92
|
+
* type R = IsNotEqual<[any], [1]> // true
|
|
93
|
+
* type R = IsNotEqual<{ a: 1 }, { a: 1; b: 2 }> // true
|
|
94
94
|
* ```
|
|
95
95
|
*
|
|
96
96
|
* Note that intersection type checks only works at first level.
|
package/ts/functional/context.ts
CHANGED
|
@@ -57,7 +57,7 @@ function contextBuilder(init: ContextBaseShape, extenders: Array<[ContextExtende
|
|
|
57
57
|
},
|
|
58
58
|
build() {
|
|
59
59
|
return extenders.reduce((p, [t], i) => {
|
|
60
|
-
const v = typeof t === 'function' ? (extenders[i][0] = t(p)) : t
|
|
60
|
+
const v = typeof t === 'function' ? (extenders[i]![0] = t(p)) : t
|
|
61
61
|
return { ...p, ...v }
|
|
62
62
|
}, init)
|
|
63
63
|
}
|
package/ts/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { required, requiredDeep, unpartial } from 'unpartial'
|
|
2
|
-
export type { IsAnyOrNever } from './any/any_or_never.js'
|
|
3
1
|
export type { AnyType, IsAny, IsNotAny, NotAnyType } from './any/any_type.js'
|
|
4
2
|
export type { At } from './array/array.at.js'
|
|
5
3
|
export type { Concat } from './array/array.concat.js'
|
|
@@ -40,6 +38,7 @@ export * from './functional/index.js'
|
|
|
40
38
|
export type { JSONArray, JSONObject, JSONPrimitive, JSONTypes } from './json.js'
|
|
41
39
|
export type { Abs, Add, Decrement, GreaterThan, Increment, Max, Multiply, Subtract } from './math/index.js'
|
|
42
40
|
export * as MathPlus from './math/math_plus.js'
|
|
41
|
+
export type { AnyOrNeverType, IsAnyOrNever } from './mix_types/any_or_never_type.js'
|
|
43
42
|
export type { IsNever, IsNotNever, Is_Never, NeverType, NotNeverType, Not_Never } from './never/never_type.js'
|
|
44
43
|
export * from './nodejs/index.js'
|
|
45
44
|
export * from './nominal/index.js'
|
|
@@ -97,5 +96,7 @@ export type {
|
|
|
97
96
|
} from './undefined/undefined_type.js'
|
|
98
97
|
export type { UnionKeys } from './union_keys.js'
|
|
99
98
|
export type { IsNotUnknown, IsUnknown, NotUnknownType, UnknownType } from './unknown/unknown_type.js'
|
|
99
|
+
export * from './unpartial.js'
|
|
100
100
|
export * from './utils/index.js'
|
|
101
101
|
export type { IsNotVoid, IsVoid, NotVoidType, VoidType } from './void/void_type.js'
|
|
102
|
+
|
|
@@ -319,7 +319,6 @@ export namespace DigitsStruct {
|
|
|
319
319
|
|
|
320
320
|
/**
|
|
321
321
|
* This is used to align the `NumberStruct` during `Add/Subtract`.
|
|
322
|
-
* @internal
|
|
323
322
|
*/
|
|
324
323
|
export type GetMinPadEnd<
|
|
325
324
|
A extends number,
|
|
@@ -382,7 +381,6 @@ export namespace DigitArray {
|
|
|
382
381
|
*
|
|
383
382
|
* This is used in various places so that there will be less computation,
|
|
384
383
|
* and the sign bit can be handled properly.
|
|
385
|
-
* @internal
|
|
386
384
|
*/
|
|
387
385
|
export type TrimLeadingZeros<T extends number[]> = T extends [0]
|
|
388
386
|
? T
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { IsNever } from '../never/never_type.js'
|
|
2
|
+
import type { IsAny } from '../any/any_type.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 🐾 Parse `T` to ensure it is either exactly `any` or exactly `never`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* type R = AnyType<any> // any
|
|
10
|
+
*
|
|
11
|
+
* type R = AnyType<never> // never
|
|
12
|
+
* type R = AnyType<unknown> // never
|
|
13
|
+
* type R = AnyType<string | boolean> // never
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type AnyOrNeverType<T, Then = T, Else = never> = IsNever<T, Then, IsAny<T, Then, Else>>
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 🎭 Validate if `T` is either exactly `any` or exactly `never`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* type R = IsAnyOrNever<any> // true
|
|
24
|
+
* type R = IsAnyOrNever<never> // true
|
|
25
|
+
*
|
|
26
|
+
* type R = IsAnyOrNever<1> // false
|
|
27
|
+
* type R = IsAnyOrNever<unknown> // false
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type IsAnyOrNever<T, Then = true, Else = false> = IsNever<T, Then, IsAny<T, Then, Else>>
|
package/ts/number/number_type.ts
CHANGED
package/ts/numeric/integer.ts
CHANGED
package/ts/object/ANotB.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { IsEqual } from '../equal/equal.js'
|
|
|
2
2
|
import type { AnyRecord } from './AnyRecord.js'
|
|
3
3
|
import type { IsDisjoint } from './IsDisjoint.js'
|
|
4
4
|
import type { KeysWithDiffType } from './KeysWithDiffType.js'
|
|
5
|
+
import type { Properties } from './properties.js'
|
|
5
6
|
|
|
6
7
|
export type ANotB<A extends AnyRecord, B extends AnyRecord> = IsEqual<A, B> extends true
|
|
7
8
|
? never
|
|
@@ -15,4 +16,4 @@ export type LeftJoin<A extends AnyRecord, B extends AnyRecord> = IsEqual<A, B> e
|
|
|
15
16
|
? A
|
|
16
17
|
: IsDisjoint<A, B> extends true
|
|
17
18
|
? A & B
|
|
18
|
-
: { [k in Exclude<keyof A, keyof B>]: A[k] } & { [k in keyof B]: B[k] }
|
|
19
|
+
: Properties<{ [k in Exclude<keyof A, keyof B>]: A[k] } & { [k in keyof B]: B[k] }>
|
package/ts/object/Required.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Thanks [jack-williams](https://github.com/jack-williams) for the [solution](https://github.com/Microsoft/TypeScript/issues/29269#issuecomment-451602962)
|
|
2
2
|
|
|
3
|
-
import { NonUndefined } from '../utils/NonUndefined.js'
|
|
3
|
+
import type { NonUndefined } from '../utils/NonUndefined.js'
|
|
4
4
|
|
|
5
5
|
export type Required<T> = { [P in keyof T]-?: NonUndefined<T[P]> }
|
|
6
6
|
|
package/ts/object/findKey.ts
CHANGED
package/ts/object/forEachKey.ts
CHANGED
package/ts/object/hasProperty.ts
CHANGED
package/ts/object/object_type.ts
CHANGED
package/ts/object/split.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AnyRecord } from './AnyRecord.js'
|
|
|
3
3
|
import type { Omit } from './omit.js'
|
|
4
4
|
import { reduceByKey } from './reduceKey.js'
|
|
5
5
|
import type { Partial } from './Partial.js'
|
|
6
|
-
import { NonUndefined } from '../utils/NonUndefined.js'
|
|
6
|
+
import type { NonUndefined } from '../utils/NonUndefined.js'
|
|
7
7
|
|
|
8
8
|
type Splitter<T extends AnyRecord> = Partial<{ [k in keyof T]: T[k] | undefined }>
|
|
9
9
|
export type Split<T extends AnyRecord, S extends AnyRecord> = {
|
package/ts/primitive.ts
CHANGED
package/ts/string/string_type.ts
CHANGED
package/ts/symbol/symbol_type.ts
CHANGED
package/ts/testing/stub.ts
CHANGED
|
@@ -5,7 +5,10 @@ import type { NoInfer } from '../type/no_infer.js'
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* stub a value.
|
|
8
|
+
*
|
|
8
9
|
* If the value is a function, it will be passed through as-is.
|
|
10
|
+
*
|
|
11
|
+
* 🦴 `utilities`
|
|
9
12
|
*/
|
|
10
13
|
export function stub<T extends AnyFunction>(stub: T): T
|
|
11
14
|
export function stub<T>(stub: RecursivePartial<NoInfer<T>>): T
|
package/ts/type/failed.ts
CHANGED
|
@@ -27,6 +27,6 @@ export interface Failed<Msg extends string> {
|
|
|
27
27
|
*
|
|
28
28
|
* It's recommended to create custom failed types instead of using this to provide better message.
|
|
29
29
|
*/
|
|
30
|
-
export interface FailedT<Msg extends string,
|
|
30
|
+
export interface FailedT<Msg extends string, _T> {
|
|
31
31
|
[uniSym]: Msg
|
|
32
32
|
}
|
package/ts/type/no_infer.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { IsNull } from '../null/null_type.js'
|
|
2
|
-
import { Or } from '../predicates/logical.js'
|
|
3
|
-
import { IsUndefined } from '../undefined/undefined_type.js'
|
|
1
|
+
import type { IsNull } from '../null/null_type.js'
|
|
2
|
+
import type { Or } from '../predicates/logical.js'
|
|
3
|
+
import type { IsUndefined } from '../undefined/undefined_type.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Prevents inference of a type parameter `T`.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* @see https://github.com/microsoft/TypeScript/pull/52968
|
|
8
|
+
* 🦴 *utilities*
|
|
10
9
|
*
|
|
11
|
-
* @
|
|
10
|
+
* @ajafff original version author
|
|
11
|
+
* @see https://github.com/microsoft/TypeScript/issues/14829#issuecomment-298425341
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
@@ -20,5 +20,8 @@ import { IsUndefined } from '../undefined/undefined_type.js'
|
|
|
20
20
|
* assertEqual(123, 'abc') // Error
|
|
21
21
|
* assertEqual({ x: 1 }, { x: 1, y: 2 }) // Error
|
|
22
22
|
* ```
|
|
23
|
+
*
|
|
24
|
+
* A build-in `NoInfer` is coming soon.
|
|
25
|
+
* @see https://github.com/microsoft/TypeScript/pull/52968
|
|
23
26
|
*/
|
|
24
27
|
export type NoInfer<T> = Or<IsNull<T>, IsUndefined<T>, T, T & {}>
|
package/ts/type-guard/is_type.ts
CHANGED
|
@@ -36,7 +36,7 @@ function isNever<S extends never>(): unknown
|
|
|
36
36
|
* @deprecated use `isType<T>()` or `testType.never<T>()` instead
|
|
37
37
|
*/
|
|
38
38
|
function isNever(subject: never): subject is never
|
|
39
|
-
function isNever(
|
|
39
|
+
function isNever(_subject?: unknown): _subject is never {
|
|
40
40
|
return true
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -49,4 +49,4 @@ isType.never = isNever
|
|
|
49
49
|
*
|
|
50
50
|
* @deprecated use `testType.equal()` instead
|
|
51
51
|
*/
|
|
52
|
-
isType.equal = function <
|
|
52
|
+
isType.equal = function <_C extends IsEqual<A, B>, A, B>() {}
|
package/ts/unpartial.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { required, requiredDeep, unpartial } from 'unpartial'
|
package/ts/void/void_type.ts
CHANGED