ts-type 3.0.12 → 3.0.14
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/CHANGELOG.md +46 -0
- package/lib/_build-in.js.map +1 -1
- package/lib/generic.js.map +1 -1
- package/lib/helper/array/readonly.js.map +1 -1
- package/lib/helper/conditional.js.map +1 -1
- package/lib/helper/deep-map.js.map +1 -1
- package/lib/helper/filter.d.ts +165 -0
- package/lib/helper/filter.js.map +1 -1
- package/lib/helper/infer.js.map +1 -1
- package/lib/helper/intersection.js.map +1 -1
- package/lib/helper/key-value.d.ts +42 -5
- package/lib/helper/key-value.js.map +1 -1
- package/lib/helper/number.js.map +1 -1
- package/lib/helper/readonly.js.map +1 -1
- package/lib/helper/record/enum.js.map +1 -1
- package/lib/helper/record/member.d.ts +132 -2
- package/lib/helper/record/member.js.map +1 -1
- package/lib/helper/record/omit-index.js.map +1 -1
- package/lib/helper/record/partial.js.map +1 -1
- package/lib/helper/record/pick-type.js.map +1 -1
- package/lib/helper/record.js.map +1 -1
- package/lib/helper/string/infer.js.map +1 -1
- package/lib/helper/string/literal-string.js.map +1 -1
- package/lib/helper/string/operations.js.map +1 -1
- package/lib/helper/string.js.map +1 -1
- package/lib/helper/tuple.js.map +1 -1
- package/lib/helper/typeof.js.map +1 -1
- package/lib/helper.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/internal/filter.js.map +1 -1
- package/lib/internal/logic/string-literal.js.map +1 -1
- package/lib/logic/any.js.map +1 -1
- package/lib/logic/never.js.map +1 -1
- package/lib/logic/record/empty.js.map +1 -1
- package/lib/logic/union/index.js.map +1 -1
- package/lib/type/base.js.map +1 -1
- package/lib/type/generator.js.map +1 -1
- package/lib/type/iterator.js.map +1 -1
- package/lib/type/promise.js.map +1 -1
- package/lib/type/proxy.js.map +1 -1
- package/lib/type/record/empty.js.map +1 -1
- package/lib/type/record/enum.js.map +1 -1
- package/lib/type/record/partial.js.map +1 -1
- package/lib/type/record/readonly.js.map +1 -1
- package/lib/type/record/union.d.ts +135 -0
- package/lib/type/record/union.js +27 -0
- package/lib/type/record/union.js.map +1 -0
- package/lib/type/record.d.ts +32 -24
- package/lib/type/record.js.map +1 -1
- package/lib/type/tuple/empty.js.map +1 -1
- package/package.json +15 -12
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ITSKeyOfUnion, ITSValueOfUnion } from "../../helper/key-value";
|
|
2
|
+
import { ITSPartialPick, ITSRequiredPick } from "../record";
|
|
3
|
+
/**
|
|
4
|
+
* Makes the selected properties optional while preserving
|
|
5
|
+
* the structure of each union member.
|
|
6
|
+
*
|
|
7
|
+
* This is the distributive Union version.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* type T =
|
|
11
|
+
* | { type: "a"; value: number }
|
|
12
|
+
* | { type: "b"; text: string };
|
|
13
|
+
*
|
|
14
|
+
* type Result = ITSPartialPickUnion<T>;
|
|
15
|
+
* // {
|
|
16
|
+
* // type?: "a";
|
|
17
|
+
* // value?: number;
|
|
18
|
+
* // } | {
|
|
19
|
+
* // type?: "b";
|
|
20
|
+
* // text?: string;
|
|
21
|
+
* // }
|
|
22
|
+
*/
|
|
23
|
+
export type ITSPartialPickUnion<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = T extends any ? {
|
|
24
|
+
[P in K & keyof T]?: T[P];
|
|
25
|
+
} : never;
|
|
26
|
+
/**
|
|
27
|
+
* Makes the selected properties required while preserving
|
|
28
|
+
* the structure of each union member.
|
|
29
|
+
*
|
|
30
|
+
* This is the distributive Union version.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* type T =
|
|
34
|
+
* | { type: "a"; value?: number }
|
|
35
|
+
* | { type: "b"; text?: string };
|
|
36
|
+
*
|
|
37
|
+
* type Result = ITSRequiredPickUnion<T>;
|
|
38
|
+
* // {
|
|
39
|
+
* // type: "a";
|
|
40
|
+
* // value: number;
|
|
41
|
+
* // } | {
|
|
42
|
+
* // type: "b";
|
|
43
|
+
* // text: string;
|
|
44
|
+
* // }
|
|
45
|
+
*/
|
|
46
|
+
export type ITSRequiredPickUnion<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = T extends any ? {
|
|
47
|
+
[P in K & keyof T]-?: T[P];
|
|
48
|
+
} : never;
|
|
49
|
+
/**
|
|
50
|
+
* Makes the selected properties optional and flattens
|
|
51
|
+
* all properties from every union member into a single object type.
|
|
52
|
+
*
|
|
53
|
+
* Unlike ITSPartialPickUnion, this does not preserve the
|
|
54
|
+
* individual union-member structure.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* type T =
|
|
58
|
+
* | { type: "a"; value: number }
|
|
59
|
+
* | { type: "b"; text: string };
|
|
60
|
+
*
|
|
61
|
+
* type Result = ITSPartialPickUnionFlat<T>;
|
|
62
|
+
* // {
|
|
63
|
+
* // type?: "a" | "b";
|
|
64
|
+
* // value?: number;
|
|
65
|
+
* // text?: string;
|
|
66
|
+
* // }
|
|
67
|
+
*/
|
|
68
|
+
export type ITSPartialPickUnionFlat<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = {
|
|
69
|
+
[P in K]?: ITSValueOfUnion<T, P>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Makes the selected properties required and flattens
|
|
73
|
+
* all members of a union into a single object type.
|
|
74
|
+
*
|
|
75
|
+
* Note: this utility intentionally makes every selected property
|
|
76
|
+
* required. For a natural flattened representation that preserves
|
|
77
|
+
* whether a property exists in every member, use a dedicated
|
|
78
|
+
* flat-base utility.
|
|
79
|
+
*/
|
|
80
|
+
export type ITSRequiredPickUnionFlat<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = {
|
|
81
|
+
[P in K]-?: ITSValueOfUnion<T, P>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Makes the specified properties required for each member
|
|
85
|
+
* of a union while preserving the union-member structure.
|
|
86
|
+
*
|
|
87
|
+
* Other properties are preserved unchanged.
|
|
88
|
+
*/
|
|
89
|
+
export type ITSRequiredWithUnion<T, K extends ITSKeyOfUnion<T>> = T extends any ? K extends keyof T ? Omit<T, K> & ITSRequiredPick<T, K> : T : never;
|
|
90
|
+
/**
|
|
91
|
+
* Makes the specified properties optional for each member
|
|
92
|
+
* of a union while preserving the union-member structure.
|
|
93
|
+
*
|
|
94
|
+
* Other properties are preserved unchanged.
|
|
95
|
+
*/
|
|
96
|
+
export type ITSPartialWithUnion<T, K extends ITSKeyOfUnion<T>> = T extends any ? K extends keyof T ? Omit<T, K> & ITSPartialPick<T, K> : T : never;
|
|
97
|
+
export type ITSUnionFlat<T> = {
|
|
98
|
+
[P in ITSKeyOfUnionRequired<T>]-?: ITSValueOfUnion<T, P>;
|
|
99
|
+
} & {
|
|
100
|
+
[P in ITSKeyOfUnionOptional<T>]?: ITSValueOfUnion<T, P>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Checks whether K is required in every member of T.
|
|
104
|
+
*/
|
|
105
|
+
export type ITSIsRequiredInUnion<T, K extends ITSKeyOfUnion<T>> = false extends (T extends unknown ? K extends keyof T ? {} extends Pick<T, K> ? false : true : false : never) ? false : true;
|
|
106
|
+
/**
|
|
107
|
+
* Gets keys that are required in every member of T.
|
|
108
|
+
*/
|
|
109
|
+
export type ITSKeyOfUnionRequired<T> = {
|
|
110
|
+
[K in ITSKeyOfUnion<T>]: ITSIsRequiredInUnion<T, K> extends true ? K : never;
|
|
111
|
+
}[ITSKeyOfUnion<T>];
|
|
112
|
+
/**
|
|
113
|
+
* Gets keys that are not required in every member of T.
|
|
114
|
+
*/
|
|
115
|
+
export type ITSKeyOfUnionOptional<T> = Exclude<ITSKeyOfUnion<T>, ITSKeyOfUnionRequired<T>>;
|
|
116
|
+
/**
|
|
117
|
+
* Makes the specified properties required and flattens
|
|
118
|
+
* all members of a union into a single object type.
|
|
119
|
+
*
|
|
120
|
+
* Other properties from all union members are preserved as
|
|
121
|
+
* optional properties because they may not exist in every member.
|
|
122
|
+
*/
|
|
123
|
+
export type ITSPartialWithUnionFlat<T, K extends ITSKeyOfUnion<T>> = Omit<ITSUnionFlat<T>, K> & {
|
|
124
|
+
[P in K]?: ITSValueOfUnion<T, P>;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Makes the specified properties optional and flattens
|
|
128
|
+
* all members of a union into a single object type.
|
|
129
|
+
*
|
|
130
|
+
* Other properties from all union members are preserved as
|
|
131
|
+
* optional properties because they may not exist in every member.
|
|
132
|
+
*/
|
|
133
|
+
export type ITSRequiredWithUnionFlat<T, K extends ITSKeyOfUnion<T>> = Omit<ITSUnionFlat<T>, K> & {
|
|
134
|
+
[P in K]-?: ITSValueOfUnion<T, P>;
|
|
135
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
ITSPartialPick / ITSRequiredPick
|
|
4
|
+
└─ 一般 Object
|
|
5
|
+
└─ keyof T
|
|
6
|
+
|
|
7
|
+
ITSPartialPickUnion / ITSRequiredPickUnion
|
|
8
|
+
└─ Union
|
|
9
|
+
└─ 保留 A | B 結構
|
|
10
|
+
└─ distributive conditional type
|
|
11
|
+
|
|
12
|
+
ITSPartialPickUnionFlat / ITSRequiredPickUnionFlat
|
|
13
|
+
└─ UnionFlat
|
|
14
|
+
└─ A | B → 單一 Object
|
|
15
|
+
└─ ITSKeyOfUnion + ITSValueOfUnion
|
|
16
|
+
|
|
17
|
+
PartialWith
|
|
18
|
+
→ 修改 K,保留 Object
|
|
19
|
+
|
|
20
|
+
PartialWithUnion
|
|
21
|
+
→ 修改 K,保留 A | B
|
|
22
|
+
|
|
23
|
+
PartialWithUnionFlat
|
|
24
|
+
→ Flatten A | B,再只修改 K
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
//# sourceMappingURL=union.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.js","sourceRoot":"","sources":["union.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;EAuBE","sourcesContent":["/*\r\nITSPartialPick / ITSRequiredPick\r\n└─ 一般 Object\r\n └─ keyof T\r\n\r\nITSPartialPickUnion / ITSRequiredPickUnion\r\n└─ Union\r\n └─ 保留 A | B 結構\r\n └─ distributive conditional type\r\n\r\nITSPartialPickUnionFlat / ITSRequiredPickUnionFlat\r\n└─ UnionFlat\r\n └─ A | B → 單一 Object\r\n └─ ITSKeyOfUnion + ITSValueOfUnion\r\n\r\nPartialWith\r\n\t→ 修改 K,保留 Object\r\n\r\nPartialWithUnion\r\n\t→ 修改 K,保留 A | B\r\n\r\nPartialWithUnionFlat\r\n\t→ Flatten A | B,再只修改 K\r\n*/\r\n\r\nimport { ITSKeyOfUnion, ITSValueOfUnion } from \"../../helper/key-value\";\r\nimport { ITSPartialPick, ITSPartialWith, ITSRequiredPick, ITSRequiredWith } from \"../record\";\r\n\r\n/**\r\n * Makes the selected properties optional while preserving\r\n * the structure of each union member.\r\n *\r\n * This is the distributive Union version.\r\n *\r\n * @example\r\n * type T =\r\n * | { type: \"a\"; value: number }\r\n * | { type: \"b\"; text: string };\r\n *\r\n * type Result = ITSPartialPickUnion<T>;\r\n * // {\r\n * // type?: \"a\";\r\n * // value?: number;\r\n * // } | {\r\n * // type?: \"b\";\r\n * // text?: string;\r\n * // }\r\n */\r\nexport type ITSPartialPickUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? {\r\n\t\t[P in K & keyof T]?: T[P];\r\n\t}\r\n\t: never;\r\n\r\n/**\r\n * Makes the selected properties required while preserving\r\n * the structure of each union member.\r\n *\r\n * This is the distributive Union version.\r\n *\r\n * @example\r\n * type T =\r\n * | { type: \"a\"; value?: number }\r\n * | { type: \"b\"; text?: string };\r\n *\r\n * type Result = ITSRequiredPickUnion<T>;\r\n * // {\r\n * // type: \"a\";\r\n * // value: number;\r\n * // } | {\r\n * // type: \"b\";\r\n * // text: string;\r\n * // }\r\n */\r\nexport type ITSRequiredPickUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? {\r\n\t\t[P in K & keyof T]-?: T[P];\r\n\t}\r\n\t: never;\r\n\r\n/**\r\n * Makes the selected properties optional and flattens\r\n * all properties from every union member into a single object type.\r\n *\r\n * Unlike ITSPartialPickUnion, this does not preserve the\r\n * individual union-member structure.\r\n *\r\n * @example\r\n * type T =\r\n * | { type: \"a\"; value: number }\r\n * | { type: \"b\"; text: string };\r\n *\r\n * type Result = ITSPartialPickUnionFlat<T>;\r\n * // {\r\n * // type?: \"a\" | \"b\";\r\n * // value?: number;\r\n * // text?: string;\r\n * // }\r\n */\r\nexport type ITSPartialPickUnionFlat<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = {\r\n\t[P in K]?: ITSValueOfUnion<T, P>;\r\n};\r\n\r\n/**\r\n * Makes the selected properties required and flattens\r\n * all members of a union into a single object type.\r\n *\r\n * Note: this utility intentionally makes every selected property\r\n * required. For a natural flattened representation that preserves\r\n * whether a property exists in every member, use a dedicated\r\n * flat-base utility.\r\n */\r\nexport type ITSRequiredPickUnionFlat<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = {\r\n\t[P in K]-?: ITSValueOfUnion<T, P>;\r\n};\r\n\r\n// ---------------\r\n\r\n/**\r\n * Makes the specified properties required for each member\r\n * of a union while preserving the union-member structure.\r\n *\r\n * Other properties are preserved unchanged.\r\n */\r\nexport type ITSRequiredWithUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? K extends keyof T\r\n\t\t? Omit<T, K> & ITSRequiredPick<T, K>\r\n\t\t: T\r\n\t: never;\r\n\r\n/**\r\n * Makes the specified properties optional for each member\r\n * of a union while preserving the union-member structure.\r\n *\r\n * Other properties are preserved unchanged.\r\n */\r\nexport type ITSPartialWithUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? K extends keyof T\r\n\t\t? Omit<T, K> & ITSPartialPick<T, K>\r\n\t\t: T\r\n\t: never;\r\n\r\nexport type ITSUnionFlat<T> = {\r\n\t[P in ITSKeyOfUnionRequired<T>]-?: ITSValueOfUnion<T, P>;\r\n} & {\r\n\t[P in ITSKeyOfUnionOptional<T>]?: ITSValueOfUnion<T, P>;\r\n};\r\n\r\n/**\r\n * Checks whether K is required in every member of T.\r\n */\r\nexport type ITSIsRequiredInUnion<\r\n T,\r\n K extends ITSKeyOfUnion<T>\r\n> = false extends (\r\n T extends unknown\r\n ? K extends keyof T\r\n ? {} extends Pick<T, K>\r\n ? false\r\n : true\r\n : false\r\n : never\r\n)\r\n ? false\r\n : true;\r\n\r\n/**\r\n * Gets keys that are required in every member of T.\r\n */\r\nexport type ITSKeyOfUnionRequired<T> = {\r\n [K in ITSKeyOfUnion<T>]:\r\n ITSIsRequiredInUnion<T, K> extends true\r\n ? K\r\n : never;\r\n}[ITSKeyOfUnion<T>];\r\n\r\n/**\r\n * Gets keys that are not required in every member of T.\r\n */\r\nexport type ITSKeyOfUnionOptional<T> =\r\n Exclude<\r\n ITSKeyOfUnion<T>,\r\n ITSKeyOfUnionRequired<T>\r\n >;\r\n\r\n/**\r\n * Makes the specified properties required and flattens\r\n * all members of a union into a single object type.\r\n *\r\n * Other properties from all union members are preserved as\r\n * optional properties because they may not exist in every member.\r\n */\r\nexport type ITSPartialWithUnionFlat<\r\n T,\r\n K extends ITSKeyOfUnion<T>\r\n> = Omit<ITSUnionFlat<T>, K>\r\n & {\r\n [P in K]?: ITSValueOfUnion<T, P>;\r\n };\r\n\r\n/**\r\n * Makes the specified properties optional and flattens\r\n * all members of a union into a single object type.\r\n *\r\n * Other properties from all union members are preserved as\r\n * optional properties because they may not exist in every member.\r\n */\r\nexport type ITSRequiredWithUnionFlat<\r\n T,\r\n K extends ITSKeyOfUnion<T>\r\n> = Omit<ITSUnionFlat<T>, K>\r\n & {\r\n [P in K]-?: ITSValueOfUnion<T, P>;\r\n };"]}
|
package/lib/type/record.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Created by user on 2019/6/11.
|
|
9
9
|
*/
|
|
10
10
|
import type { ITSKeyofBothDiff, ITSKeyofBothSame, ITSKeyofDiff, ITSKeyofSame } from '../helper/filter';
|
|
11
|
+
import { ITSLogicIsNever } from '../logic/never';
|
|
11
12
|
export type { ITSRequireRecord, ITSPartialRecord } from '../type/record/partial';
|
|
12
13
|
/**
|
|
13
14
|
* 取得兩個鍵集合的差異(已棄用)
|
|
@@ -116,25 +117,40 @@ export type ITSOverwrite<T, U> = Omit<T, keyof U> & U;
|
|
|
116
117
|
*/
|
|
117
118
|
export type ITSMergeBoth<T, U> = ITSPickBothDiff<T, U> & Pick<T | U, ITSKeyofBothSame<T, U>>;
|
|
118
119
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
120
|
+
* Makes the selected properties of a type required.
|
|
121
|
+
*
|
|
122
|
+
* This is the standard version and is intended for a single object type.
|
|
121
123
|
*
|
|
122
124
|
* @example
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
125
|
+
* type User = {
|
|
126
|
+
* name?: string;
|
|
127
|
+
* age?: number;
|
|
128
|
+
* };
|
|
129
|
+
*
|
|
130
|
+
* type Result = ITSRequiredPick<User, "name">;
|
|
131
|
+
* // {
|
|
132
|
+
* // name: string;
|
|
133
|
+
* // age?: number;
|
|
134
|
+
* // }
|
|
126
135
|
*/
|
|
127
136
|
export type ITSRequiredPick<T, K extends keyof T = keyof T> = {
|
|
128
137
|
[P in K]-?: T[P];
|
|
129
138
|
};
|
|
130
139
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
140
|
+
* Makes the selected properties of a type optional.
|
|
141
|
+
*
|
|
142
|
+
* This is the standard version and is intended for a single object type.
|
|
133
143
|
*
|
|
134
144
|
* @example
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
145
|
+
* type User = {
|
|
146
|
+
* name: string;
|
|
147
|
+
* age: number;
|
|
148
|
+
* };
|
|
149
|
+
*
|
|
150
|
+
* type Result = ITSPartialPick<User, "name">;
|
|
151
|
+
* // {
|
|
152
|
+
* // name?: string;
|
|
153
|
+
* // }
|
|
138
154
|
*/
|
|
139
155
|
export type ITSPartialPick<T, K extends keyof T = keyof T> = {
|
|
140
156
|
[P in K]?: T[P];
|
|
@@ -178,25 +194,17 @@ export type ITSPickExtra2<T, PK extends keyof T, RK extends Exclude<keyof T, PK>
|
|
|
178
194
|
*/
|
|
179
195
|
export type ITSPickAndPartialOther<T, RK extends keyof T, PK extends Exclude<keyof T, RK> = Exclude<keyof T, RK>> = Pick<T, RK> & ITSPartialPick<T, PK>;
|
|
180
196
|
/**
|
|
181
|
-
*
|
|
182
|
-
* Keep specified keys as Required, other keys unchanged
|
|
197
|
+
* Makes the specified properties required while preserving all other properties.
|
|
183
198
|
*
|
|
184
|
-
*
|
|
185
|
-
* interface User { name: string; age: number; email: string; }
|
|
186
|
-
* type Result = ITSRequiredWith<User, 'name'>;
|
|
187
|
-
* // type Result = { name: string; age: number; email: string; }
|
|
199
|
+
* If `K` is `never`, `T` is returned unchanged.
|
|
188
200
|
*/
|
|
189
|
-
export type ITSRequiredWith<T, K extends keyof T> = Omit<T, K> & ITSRequiredPick<T, K>;
|
|
201
|
+
export type ITSRequiredWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true ? T : Omit<T, K> & ITSRequiredPick<T, K>;
|
|
190
202
|
/**
|
|
191
|
-
*
|
|
192
|
-
* Keep specified keys as Partial, other keys unchanged
|
|
203
|
+
* Makes the specified properties optional while preserving all other properties.
|
|
193
204
|
*
|
|
194
|
-
*
|
|
195
|
-
* interface User { name: string; age: number; email: string; }
|
|
196
|
-
* type Result = ITSPartialWith<User, 'name'>;
|
|
197
|
-
* // type Result = { name?: string; age: number; email: string; }
|
|
205
|
+
* If `K` is `never`, `T` is returned unchanged.
|
|
198
206
|
*/
|
|
199
|
-
export type ITSPartialWith<T, K extends keyof T> = Omit<T, K> & ITSPartialPick<T, K>;
|
|
207
|
+
export type ITSPartialWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true ? T : Omit<T, K> & ITSPartialPick<T, K>;
|
|
200
208
|
/**
|
|
201
209
|
* 確保物件至少具有指定的鍵集合中的一個
|
|
202
210
|
* Ensure the object has at least one of the specified key sets
|
package/lib/type/record.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["record.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 記錄(Record)類型操作工具\n * Record Type Manipulation Utilities\n
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["record.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 記錄(Record)類型操作工具\n * Record Type Manipulation Utilities\n *\n * 提供物件類型選擇、覆寫、合併等操作\n * Provides object type selection, overwrite, merge and other operations\n *\n * Created by user on 2019/6/11.\n */\n\nimport type { ITSKeyofBothDiff, ITSKeyofBothSame, ITSKeyofDiff, ITSKeyofSame } from '../helper/filter';\nimport { ITSLogicIsNever } from '../logic/never';\n\nexport type { ITSRequireRecord, ITSPartialRecord } from '../type/record/partial';\n\n/**\n * 取得兩個鍵集合的差異(已棄用)\n * Get the difference between two key sets (deprecated)\n *\n * @deprecated 請使用 ITSKeyofDiff 取代 / Please use ITSKeyofDiff instead\n */\nexport type ITSDiff<T extends keyof any, U extends keyof any> = (\n\t{ [P in T]: P }\n\t&\n\t{ [P in U]: never }\n\t&\n\t{ [x: string]: never }\n\t)[T];\n\n/**\n * 選擇 T 中與 U 相同的鍵\n * Pick keys from T that are the same as U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickSame<A, B>;\n * // type Result = { a: 1 }\n */\nexport type ITSPickSame<T, U> = Pick<T, ITSKeyofSame<T, U>>;\n\n/**\n * 選擇 T 中與 U 不同的鍵\n * Pick keys from T that are different from U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickDiff<A, B>;\n * // type Result = { b: 2 }\n */\nexport type ITSPickDiff<T, U> = Pick<T, ITSKeyofDiff<T, U>>;\n\n/**\n * 選擇 T 與 U 中同時存在的鍵\n * Pick keys that exist in both T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickBothSame<A, B>;\n * // type Result = { a: 1 }\n */\nexport type ITSPickBothSame<T, U> = Pick<T & U, ITSKeyofBothSame<T, U>>;\n\n/**\n * 選擇 T 與 U 中不同時存在的鍵\n * Pick keys that do not exist in both T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickBothDiff<A, B>;\n * // type Result = { b: 2; c: 4 }\n */\nexport type ITSPickBothDiff<T, U> = Pick<T & U, ITSKeyofBothDiff<T, U>>;\n\n/**\n * 選擇指定鍵集合 K(必須是 T 與 U 中同時存在的鍵)\n * Pick a specified key set K (must be keys that exist in both T and U)\n */\nexport type ITSPickBoth<T, U, K extends ITSKeyofBothSame<T, U> = ITSKeyofBothSame<T, U>> = Pick<T & U, K>;\n\n/**\n * 取得物件成員的類型\n * Get the type of an object member\n *\n * @see https://stackoverflow.com/questions/49198713/override-the-properties-of-an-interface-in-typescript\n */\nexport type ITSPickMember<T, K extends keyof T> = T[K];\n\n/**\n * 排除指定鍵(已棄用)\n * Exclude specified keys (deprecated)\n *\n * @deprecated 請使用 Omit 取代 / Please use Omit instead\n */\nexport type ITSPickNot<T, K extends keyof T> = Omit<T, K>;\n\n/**\n * 覆寫物件類型的屬性\n * Overwrite properties of an object type\n *\n * 用 U 中的屬性覆寫 T 中的同名屬性\n * Overwrites properties in T with the same name from U\n *\n * @see https://stackoverflow.com/questions/49198713/override-the-properties-of-an-interface-in-typescript\n *\n * @example\n * interface A1 { s: string }\n * type A2 = ITSOverwrite<A1, { s: number }>;\n * // type A2 = { s: number }\n */\nexport type ITSOverwrite<T, U> = Omit<T, keyof U> & U;\n\n/**\n * 合併兩個物件類型,處理衝突屬性\n * Merge two object types, handling conflicting properties\n *\n * 對於 T 與 U 中同時存在的鍵,取兩者的聯集類型\n * For keys that exist in both T and U, takes the union type of both\n *\n * @example\n * type Test1 = { id: number, code: string }\n * type Test2 = { id: string, code: number }\n * type Test3 = ITSMergeBoth<Test1, Test2>\n * // type Test3 = { id: string | number; code: string | number }\n * @see https://github.com/microsoft/TypeScript/issues/35627\n */\nexport type ITSMergeBoth<T, U> = ITSPickBothDiff<T, U> & Pick<T | U, ITSKeyofBothSame<T, U>>;\n\n/**\n * Makes the selected properties of a type required.\n *\n * This is the standard version and is intended for a single object type.\n *\n * @example\n * type User = {\n * name?: string;\n * age?: number;\n * };\n *\n * type Result = ITSRequiredPick<User, \"name\">;\n * // {\n * // name: string;\n * // age?: number;\n * // }\n */\nexport type ITSRequiredPick<T, K extends keyof T = keyof T> = {\n\t[P in K]-?: T[P];\n};\n\n/**\n * Makes the selected properties of a type optional.\n *\n * This is the standard version and is intended for a single object type.\n *\n * @example\n * type User = {\n * name: string;\n * age: number;\n * };\n *\n * type Result = ITSPartialPick<User, \"name\">;\n * // {\n * // name?: string;\n * // }\n */\nexport type ITSPartialPick<T, K extends keyof T = keyof T> = {\n\t[P in K]?: T[P];\n};\n\n/**\n * 複製類型並將指定鍵RK設為必填,其他鍵Pk設為可選\n * Clone a type and mark specified keys as Required, other keys as Partial\n *\n * @example\n * interface User { name: string; age: number; email: string; }\n * type Result = ITSPickExtra<User, 'name', 'email'>;\n * // type Result = { name: string; } & { age?: number; email?: string; }\n */\nexport type ITSPickExtra<T, RK extends keyof T, PK extends Exclude<keyof T, RK> = Exclude<keyof T, RK>> =\n\tITSRequiredPick<T, RK>\n\t& ITSPartialPick<T, PK>;\n\n/**\n * 複製類型並將指定鍵Pk設為可選,其他鍵Rk設為必填(與 ITSPickExtra 相反)\n * Clone a type and mark specified keys as Partial, other keys as Required (opposite of ITSPickExtra)\n *\n * @example\n * interface User { name: string; age: number; email: string; }\n * type Result = ITSPickExtra2<User, 'name', 'email'>;\n * // type Result = { name?: string; } & { age: number; email: string; }\n */\nexport type ITSPickExtra2<T, PK extends keyof T, RK extends Exclude<keyof T, PK> = Exclude<keyof T, PK>> =\n\tITSRequiredPick<T, RK>\n\t& ITSPartialPick<T, PK>;\n\n/**\n * 保留指定鍵不變(維持原本的必選/可選/唯讀屬性),其他鍵變為可選\n * Keep specified keys unchanged (preserving required/optional/readonly modifiers), other keys become Partial\n *\n * 與 ITSPickExtra 的差異:ITSPickExtra 會將指定鍵強制設為必填,而此類型保留原始修飾符\n * Difference from ITSPickExtra: ITSPickExtra forces specified keys to Required, while this type preserves original modifiers\n *\n * @see {@link ITSPickExtra} - 將指定鍵設為必填,其他鍵可選\n * @see {@link ITSPartialWith} - 將指定鍵設為可選,其他鍵不變\n *\n * @example\n * interface User { name: string; readonly id: string; age?: number; email: string; }\n * type Result = ITSPickAndPartialOther<User, 'name' | 'id'>;\n * // 輸出結果 / Output:\n * // { name: string; readonly id: string; } & { age?: number; email?: string; }\n * // 注意:name 維持必選,id 維持唯讀且必選,age 和 email 變為可選\n */\nexport type ITSPickAndPartialOther<T, RK extends keyof T, PK extends Exclude<keyof T, RK> = Exclude<keyof T, RK>> =\n\tPick<T, RK>\n\t& ITSPartialPick<T, PK>;\n\n/**\n * Makes the specified properties required while preserving all other properties.\n *\n * If `K` is `never`, `T` is returned unchanged.\n */\nexport type ITSRequiredWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true\n\t? T\n\t: Omit<T, K> & ITSRequiredPick<T, K>;\n\n/**\n * Makes the specified properties optional while preserving all other properties.\n *\n * If `K` is `never`, `T` is returned unchanged.\n */\nexport type ITSPartialWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true\n\t? T\n\t: Omit<T, K> & ITSPartialPick<T, K>;\n\n/**\n * 確保物件至少具有指定的鍵集合中的一個\n * Ensure the object has at least one of the specified key sets\n *\n * @see https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist\n *\n * @example\n * interface User { name?: string; age?: number; }\n * type AtLeastOne = ITSRequireAtLeastOne<User, 'name' | 'age'>;\n * // 需要至少提供 name 或 age 其中一個\n */\nexport type ITSRequireAtLeastOne<T, Keys extends keyof T = keyof T> =\n\tOmit<T, Keys>\n\t& {\n\t[K in Keys]-?: ITSRequiredPick<T, K>\n\t& ITSPartialPick<T, Exclude<Keys, K>>\n}[Keys];\n\n/**\n * 確保物件只能具有指定的鍵集合中的其中一個(互斥)\n * Ensure the object can only have exactly one of the specified key sets (mutually exclusive)\n *\n * @see https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist\n * @see {@link ITSPickOne} 另一種實現方式,使用 `void` 作為其餘鍵的類型\n *\n * @example\n * interface User { name?: string; age?: number; }\n * type OnlyOne1 = ITSRequireOnlyOne<User, 'name' | 'age'>;\n * // 輸出結果:\n * // type OnlyOne1 = { name: string; age?: never; } | { age: number; name?: never; }\n * // 只能提供 name 或 age 其中一個,不能同時提供\n */\nexport type ITSRequireOnlyOne<T, Keys extends keyof T = keyof T> =\n\tOmit<T, Keys>\n\t& {\n\t[K in Keys]-?: ITSRequiredPick<T, K>\n\t& Partial<Record<Exclude<Keys, K>, never>>\n}[Keys];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 空元組類型\n * Empty Tuple Type\n
|
|
1
|
+
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 空元組類型\n * Empty Tuple Type\n *\n * 提供空元組相關的類型定義\n * Provides empty tuple-related type definitions\n */\n\nimport { ITSArrayListMaybeReadonly } from '../base';\n\n/**\n * 空元組類型\n * Empty tuple type\n *\n * @example\n * type Empty = ITSEmptyTuple;\n * // type Empty = [] | readonly []\n */\nexport type ITSEmptyTuple = ITSArrayListMaybeReadonly<never>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-type",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"description": "TypeScript 類型工具庫:提供豐富的類型操作工具和重新導出的內建類型 / TypeScript type utility library: provides rich type manipulation utilities and re-exported built-in types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
".d.ts",
|
|
@@ -56,20 +56,20 @@
|
|
|
56
56
|
"test": "test"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
|
-
"coverage": "
|
|
60
|
-
"pretest": "
|
|
61
|
-
"test": "
|
|
59
|
+
"coverage": "pnpm run test --coverage",
|
|
60
|
+
"pretest": "pnpm run build",
|
|
61
|
+
"test": "pnpm run ts:check && pnpm run test:tsd",
|
|
62
62
|
"test:jest": "jest --passWithNoTests",
|
|
63
63
|
"test:jest:coverage": "node --run test:jest -- --coverage",
|
|
64
|
-
"test:jest:snapshot": "
|
|
65
|
-
"test:snapshot": "
|
|
64
|
+
"test:jest:snapshot": "pnpm run test:jest -u",
|
|
65
|
+
"test:snapshot": "pnpm run test -u",
|
|
66
66
|
"test:tsd": "tsd",
|
|
67
|
-
"build": "
|
|
68
|
-
"build-lib-toc": "
|
|
67
|
+
"build": "pnpm run build-lib-toc && tsc",
|
|
68
|
+
"build-lib-toc": "tsx ./test/script/toc && pnpm run build:toc",
|
|
69
69
|
"build:toc": "tsc --skipLibCheck & echo build:toc",
|
|
70
|
-
"preversion": "
|
|
70
|
+
"preversion": "pnpm run test && pnpm run postpublish:git:commit",
|
|
71
71
|
"prepublishOnly": "echo prepublishOnly",
|
|
72
|
-
"postpublish:git:commit": "git commit -m \"build(release): publish\" ./lib/index.d.ts & echo postpublish:git:commit",
|
|
72
|
+
"postpublish:git:commit": "git commit -m \"build(release): publish\" ./lib/index.d.ts ./lib & echo postpublish:git:commit",
|
|
73
73
|
"ncu": "yarn-tool ncu -u",
|
|
74
74
|
"sort-package-json": "yarn-tool sort",
|
|
75
75
|
"ts:check": "tsc -p tsconfig.check.json --emitDeclarationOnly --skipLibCheck",
|
|
@@ -91,11 +91,14 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@types/node": "*",
|
|
94
|
-
"tslib": ">=2",
|
|
94
|
+
"tslib": ">=2.8.1",
|
|
95
95
|
"typedarray-dts": "^1.0.0"
|
|
96
96
|
},
|
|
97
|
+
"devDependencies": {
|
|
98
|
+
"@ts-type/object-freeze": "^1.0.14"
|
|
99
|
+
},
|
|
97
100
|
"peerDependencies": {
|
|
98
101
|
"ts-toolbelt": "^9.6.0"
|
|
99
102
|
},
|
|
100
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "673857cff12964d50e2da0224bd21fcf06c7744b"
|
|
101
104
|
}
|