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.
Files changed (51) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/lib/_build-in.js.map +1 -1
  3. package/lib/generic.js.map +1 -1
  4. package/lib/helper/array/readonly.js.map +1 -1
  5. package/lib/helper/conditional.js.map +1 -1
  6. package/lib/helper/deep-map.js.map +1 -1
  7. package/lib/helper/filter.d.ts +165 -0
  8. package/lib/helper/filter.js.map +1 -1
  9. package/lib/helper/infer.js.map +1 -1
  10. package/lib/helper/intersection.js.map +1 -1
  11. package/lib/helper/key-value.d.ts +42 -5
  12. package/lib/helper/key-value.js.map +1 -1
  13. package/lib/helper/number.js.map +1 -1
  14. package/lib/helper/readonly.js.map +1 -1
  15. package/lib/helper/record/enum.js.map +1 -1
  16. package/lib/helper/record/member.d.ts +132 -2
  17. package/lib/helper/record/member.js.map +1 -1
  18. package/lib/helper/record/omit-index.js.map +1 -1
  19. package/lib/helper/record/partial.js.map +1 -1
  20. package/lib/helper/record/pick-type.js.map +1 -1
  21. package/lib/helper/record.js.map +1 -1
  22. package/lib/helper/string/infer.js.map +1 -1
  23. package/lib/helper/string/literal-string.js.map +1 -1
  24. package/lib/helper/string/operations.js.map +1 -1
  25. package/lib/helper/string.js.map +1 -1
  26. package/lib/helper/tuple.js.map +1 -1
  27. package/lib/helper/typeof.js.map +1 -1
  28. package/lib/helper.js.map +1 -1
  29. package/lib/index.d.ts +1 -0
  30. package/lib/internal/filter.js.map +1 -1
  31. package/lib/internal/logic/string-literal.js.map +1 -1
  32. package/lib/logic/any.js.map +1 -1
  33. package/lib/logic/never.js.map +1 -1
  34. package/lib/logic/record/empty.js.map +1 -1
  35. package/lib/logic/union/index.js.map +1 -1
  36. package/lib/type/base.js.map +1 -1
  37. package/lib/type/generator.js.map +1 -1
  38. package/lib/type/iterator.js.map +1 -1
  39. package/lib/type/promise.js.map +1 -1
  40. package/lib/type/proxy.js.map +1 -1
  41. package/lib/type/record/empty.js.map +1 -1
  42. package/lib/type/record/enum.js.map +1 -1
  43. package/lib/type/record/partial.js.map +1 -1
  44. package/lib/type/record/readonly.js.map +1 -1
  45. package/lib/type/record/union.d.ts +135 -0
  46. package/lib/type/record/union.js +27 -0
  47. package/lib/type/record/union.js.map +1 -0
  48. package/lib/type/record.d.ts +32 -24
  49. package/lib/type/record.js.map +1 -1
  50. package/lib/type/tuple/empty.js.map +1 -1
  51. 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 };"]}
@@ -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
- * Pick specified keys and mark as Required
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
- * interface User { name?: string; age?: number; email?: string; }
124
- * type RequiredName = ITSRequiredPick<User, 'name'>;
125
- * // type RequiredName = { name: string; age?: number; email?: string; }
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
- * Pick specified keys and mark as Partial
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
- * interface User { name: string; age: number; email: string; }
136
- * type PartialName = ITSPartialPick<User, 'name'>;
137
- * // type PartialName = { name?: string; age: number; email: string; }
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
- * @example
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
- * @example
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
@@ -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 * \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';\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 * 選擇指定鍵並設為必填\n * Pick specified keys and mark as Required\n * \n * @example\n * interface User { name?: string; age?: number; email?: string; }\n * type RequiredName = ITSRequiredPick<User, 'name'>;\n * // type RequiredName = { name: string; age?: number; email?: string; }\n */\nexport type ITSRequiredPick<T, K extends keyof T = keyof T> = {\n\t[P in K]-?: T[P];\n};\n\n/**\n * 選擇指定鍵並設為可選\n * Pick specified keys and mark as Partial\n * \n * @example\n * interface User { name: string; age: number; email: string; }\n * type PartialName = ITSPartialPick<User, 'name'>;\n * // type PartialName = { name?: string; age: number; email: string; }\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>> = Pick<T, RK>\n\t& ITSPartialPick<T, PK>;\n\n/**\n * 保留指定鍵為必填,其他鍵不變\n * Keep specified keys as Required, other keys unchanged\n * \n * @example\n * interface User { name: string; age: number; email: string; }\n * type Result = ITSRequiredWith<User, 'name'>;\n * // type Result = { name: string; age: number; email: string; }\n */\nexport type ITSRequiredWith<T, K extends keyof T> = Omit<T, K> & ITSRequiredPick<T, K>;\n\n/**\n * 保留指定鍵為可選,其他鍵不變\n * Keep specified keys as Partial, other keys unchanged\n * \n * @example\n * interface User { name: string; age: number; email: string; }\n * type Result = ITSPartialWith<User, 'name'>;\n * // type Result = { name?: string; age: number; email: string; }\n */\nexport type ITSPartialWith<T, K extends keyof 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
+ {"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 * \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"]}
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.12",
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": "yarn run test -- --coverage",
60
- "pretest": "yarn run build",
61
- "test": "yarn run ts:check && yarn run test:tsd",
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": "yarn run test:jest -- -u",
65
- "test:snapshot": "yarn run test -- -u",
64
+ "test:jest:snapshot": "pnpm run test:jest -u",
65
+ "test:snapshot": "pnpm run test -u",
66
66
  "test:tsd": "tsd",
67
- "build": "yarn run build-lib-toc",
68
- "build-lib-toc": "ts-node ./test/script/toc && yarn run build: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": "yarn run test && yarn run postpublish:git:commit",
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": "68144dcde64f5288df56b29573071d1583bc7087"
103
+ "gitHead": "673857cff12964d50e2da0224bd21fcf06c7744b"
101
104
  }