ts-type 3.0.10 → 3.0.12
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 +37 -0
- package/lib/type/base.d.ts +14 -0
- package/lib/type/base.js.map +1 -1
- package/lib/type/record.d.ts +18 -0
- package/lib/type/record.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,43 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.12](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.10...ts-type@3.0.12) (2026-03-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 📚 Documentation
|
|
11
|
+
|
|
12
|
+
* 刪除 WebStorm CLI、MCP 文檔及對比文檔 ([261b92d](https://github.com/bluelovers/ws-ts-type/commit/261b92d41c26766282ec13c2c189836ad5083b51))
|
|
13
|
+
* **ts-type:** 為 ITSPickAndPartialOther 和 ITSPropertyKeyOrIndex 添加 JSDoc 註解與使用範例 ([91a189e](https://github.com/bluelovers/ws-ts-type/commit/91a189e391c029153ddfbc1656a9afa212a5ac35))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### 🛠 Build System
|
|
17
|
+
|
|
18
|
+
* **ts-type:** set `module` to `node16` in `tsconfig.check.json` ([c615a46](https://github.com/bluelovers/ws-ts-type/commit/c615a463a8552657993d698a69dbcb541b1ff4d3))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🔖 Miscellaneous
|
|
22
|
+
|
|
23
|
+
* . ([ac97bcd](https://github.com/bluelovers/ws-ts-type/commit/ac97bcde04dc40f354b24e29052b6f04ad7f1687))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## [3.0.11](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.10...ts-type@3.0.11) (2026-03-28)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### 📚 Documentation
|
|
32
|
+
|
|
33
|
+
* 刪除 WebStorm CLI、MCP 文檔及對比文檔 ([261b92d](https://github.com/bluelovers/ws-ts-type/commit/261b92d41c26766282ec13c2c189836ad5083b51))
|
|
34
|
+
* **ts-type:** 為 ITSPickAndPartialOther 和 ITSPropertyKeyOrIndex 添加 JSDoc 註解與使用範例 ([91a189e](https://github.com/bluelovers/ws-ts-type/commit/91a189e391c029153ddfbc1656a9afa212a5ac35))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### 🛠 Build System
|
|
38
|
+
|
|
39
|
+
* **ts-type:** set `module` to `node16` in `tsconfig.check.json` ([c615a46](https://github.com/bluelovers/ws-ts-type/commit/c615a463a8552657993d698a69dbcb541b1ff4d3))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
6
43
|
## [3.0.10](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.8...ts-type@3.0.10) (2026-03-15)
|
|
7
44
|
|
|
8
45
|
|
package/lib/type/base.d.ts
CHANGED
|
@@ -60,6 +60,20 @@ export type ITSValueOrArrayMaybeReadonly<T> = T | ITSArrayListMaybeReadonly<T>;
|
|
|
60
60
|
* // type PropKey = string | symbol
|
|
61
61
|
*/
|
|
62
62
|
export type ITSPropertyKey = string | symbol;
|
|
63
|
+
/**
|
|
64
|
+
* 屬性鍵或索引類型:字串、符號或數字
|
|
65
|
+
* Property key or index type: string, symbol, or number
|
|
66
|
+
*
|
|
67
|
+
* 適用於物件屬性存取與陣列索引的聯合類型
|
|
68
|
+
* Suitable for union type covering object property access and array index access
|
|
69
|
+
*
|
|
70
|
+
* @see {@link ITSPropertyKey} - 僅字串或符號(不含數字索引)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* type KeyOrIdx = ITSPropertyKeyOrIndex;
|
|
74
|
+
* // type KeyOrIdx = string | symbol | number
|
|
75
|
+
*/
|
|
76
|
+
export type ITSPropertyKeyOrIndex = ITSPropertyKey | number;
|
|
63
77
|
/**
|
|
64
78
|
* 任意函數類型
|
|
65
79
|
* Any function type
|
package/lib/type/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["base.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 基礎類型定義\n * Base Type Definitions\n * \n * 提供常用的基礎類型別名和工具類型\n * Provides commonly used base type aliases and utility types\n */\n\nimport { ITSTypeFunction } from '../generic';\n\n/**\n * 陣列類型:可讀寫陣列或唯讀陣列\n * Array type: writable array or readonly array\n * \n * @example\n * type StringList = ITSArrayListMaybeReadonly<string>;\n * // type StringList = string[] | readonly string[]\n */\nexport type ITSArrayListMaybeReadonly<T> = T[] | readonly T[];\n\n/**\n * 鍵的類型:符號、字串或數字\n * Key types: symbol, string, or number\n * \n * @example\n * type Keys = ITSKeys;\n * // type Keys = symbol | string | number\n */\nexport type ITSKeys = symbol | string | number;\n\n/**\n * 建構函數類型\n * Constructor type\n * \n * @example\n * type MyConstructor = ITSConstructorLike<MyClass>;\n * // type MyConstructor = new (...args: any) => MyClass\n */\nexport type ITSConstructorLike<T extends any = any> = new(...args: any) => T;\n\n/**\n * 值或陣列:單一值或其陣列\n * Value or array: single value or array of that value\n * \n * @example\n * type StringOrArray = ITSValueOrArray<string>;\n * // type StringOrArray = string | string[]\n */\nexport type ITSValueOrArray<T> = T | T[];\n\n/**\n * 值或可能唯讀的陣列:單一值、可讀寫陣列或唯讀陣列\n * Value or possibly readonly array: single value, writable array, or readonly array\n * \n * @example\n * type StringOrList = ITSValueOrArrayMaybeReadonly<string>;\n * // type StringOrList = string | string[] | readonly string[]\n */\nexport type ITSValueOrArrayMaybeReadonly<T> = T | ITSArrayListMaybeReadonly<T>;\n\n/**\n * 屬性鍵類型:字串或符號\n * Property key type: string or symbol\n * \n * @example\n * type PropKey = ITSPropertyKey;\n * // type PropKey = string | symbol\n */\nexport type ITSPropertyKey = string | symbol;\n\n/**\n * 任意函數類型\n * Any function type\n * \n * @example\n * type AnyFunc = ITSAnyFunction;\n * // type AnyFunc = (...args: any[]) => any\n */\nexport type ITSAnyFunction = ITSTypeFunction<any>;\n\n/**\n * 基本原始類型:數字、字串或布林值\n * Basic primitive types: number, string, or boolean\n * \n * @example\n * type Primitive = ITSBasicPrimitive;\n * // type Primitive = number | string | boolean\n */\nexport type ITSBasicPrimitive = number | string | boolean;\n\n/**\n * 可為空的原始類型:null 或 undefined\n * Nullable primitive types: null or undefined\n * \n * @example\n * type Nullish = ITSNullPrimitive;\n * // type Nullish = null | undefined\n */\nexport type ITSNullPrimitive = null | undefined;\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["base.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 基礎類型定義\n * Base Type Definitions\n * \n * 提供常用的基礎類型別名和工具類型\n * Provides commonly used base type aliases and utility types\n */\n\nimport { ITSTypeFunction } from '../generic';\n\n/**\n * 陣列類型:可讀寫陣列或唯讀陣列\n * Array type: writable array or readonly array\n * \n * @example\n * type StringList = ITSArrayListMaybeReadonly<string>;\n * // type StringList = string[] | readonly string[]\n */\nexport type ITSArrayListMaybeReadonly<T> = T[] | readonly T[];\n\n/**\n * 鍵的類型:符號、字串或數字\n * Key types: symbol, string, or number\n * \n * @example\n * type Keys = ITSKeys;\n * // type Keys = symbol | string | number\n */\nexport type ITSKeys = symbol | string | number;\n\n/**\n * 建構函數類型\n * Constructor type\n * \n * @example\n * type MyConstructor = ITSConstructorLike<MyClass>;\n * // type MyConstructor = new (...args: any) => MyClass\n */\nexport type ITSConstructorLike<T extends any = any> = new(...args: any) => T;\n\n/**\n * 值或陣列:單一值或其陣列\n * Value or array: single value or array of that value\n * \n * @example\n * type StringOrArray = ITSValueOrArray<string>;\n * // type StringOrArray = string | string[]\n */\nexport type ITSValueOrArray<T> = T | T[];\n\n/**\n * 值或可能唯讀的陣列:單一值、可讀寫陣列或唯讀陣列\n * Value or possibly readonly array: single value, writable array, or readonly array\n * \n * @example\n * type StringOrList = ITSValueOrArrayMaybeReadonly<string>;\n * // type StringOrList = string | string[] | readonly string[]\n */\nexport type ITSValueOrArrayMaybeReadonly<T> = T | ITSArrayListMaybeReadonly<T>;\n\n/**\n * 屬性鍵類型:字串或符號\n * Property key type: string or symbol\n * \n * @example\n * type PropKey = ITSPropertyKey;\n * // type PropKey = string | symbol\n */\nexport type ITSPropertyKey = string | symbol;\n\n/**\n * 屬性鍵或索引類型:字串、符號或數字\n * Property key or index type: string, symbol, or number\n *\n * 適用於物件屬性存取與陣列索引的聯合類型\n * Suitable for union type covering object property access and array index access\n *\n * @see {@link ITSPropertyKey} - 僅字串或符號(不含數字索引)\n *\n * @example\n * type KeyOrIdx = ITSPropertyKeyOrIndex;\n * // type KeyOrIdx = string | symbol | number\n */\nexport type ITSPropertyKeyOrIndex = ITSPropertyKey | number;\n\n/**\n * 任意函數類型\n * Any function type\n * \n * @example\n * type AnyFunc = ITSAnyFunction;\n * // type AnyFunc = (...args: any[]) => any\n */\nexport type ITSAnyFunction = ITSTypeFunction<any>;\n\n/**\n * 基本原始類型:數字、字串或布林值\n * Basic primitive types: number, string, or boolean\n * \n * @example\n * type Primitive = ITSBasicPrimitive;\n * // type Primitive = number | string | boolean\n */\nexport type ITSBasicPrimitive = number | string | boolean;\n\n/**\n * 可為空的原始類型:null 或 undefined\n * Nullable primitive types: null or undefined\n * \n * @example\n * type Nullish = ITSNullPrimitive;\n * // type Nullish = null | undefined\n */\nexport type ITSNullPrimitive = null | undefined;\n"]}
|
package/lib/type/record.d.ts
CHANGED
|
@@ -159,6 +159,24 @@ export type ITSPickExtra<T, RK extends keyof T, PK extends Exclude<keyof T, RK>
|
|
|
159
159
|
* // type Result = { name?: string; } & { age: number; email: string; }
|
|
160
160
|
*/
|
|
161
161
|
export type ITSPickExtra2<T, PK extends keyof T, RK extends Exclude<keyof T, PK> = Exclude<keyof T, PK>> = ITSRequiredPick<T, RK> & ITSPartialPick<T, PK>;
|
|
162
|
+
/**
|
|
163
|
+
* 保留指定鍵不變(維持原本的必選/可選/唯讀屬性),其他鍵變為可選
|
|
164
|
+
* Keep specified keys unchanged (preserving required/optional/readonly modifiers), other keys become Partial
|
|
165
|
+
*
|
|
166
|
+
* 與 ITSPickExtra 的差異:ITSPickExtra 會將指定鍵強制設為必填,而此類型保留原始修飾符
|
|
167
|
+
* Difference from ITSPickExtra: ITSPickExtra forces specified keys to Required, while this type preserves original modifiers
|
|
168
|
+
*
|
|
169
|
+
* @see {@link ITSPickExtra} - 將指定鍵設為必填,其他鍵可選
|
|
170
|
+
* @see {@link ITSPartialWith} - 將指定鍵設為可選,其他鍵不變
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* interface User { name: string; readonly id: string; age?: number; email: string; }
|
|
174
|
+
* type Result = ITSPickAndPartialOther<User, 'name' | 'id'>;
|
|
175
|
+
* // 輸出結果 / Output:
|
|
176
|
+
* // { name: string; readonly id: string; } & { age?: number; email?: string; }
|
|
177
|
+
* // 注意:name 維持必選,id 維持唯讀且必選,age 和 email 變為可選
|
|
178
|
+
*/
|
|
179
|
+
export type ITSPickAndPartialOther<T, RK extends keyof T, PK extends Exclude<keyof T, RK> = Exclude<keyof T, RK>> = Pick<T, RK> & ITSPartialPick<T, PK>;
|
|
162
180
|
/**
|
|
163
181
|
* 保留指定鍵為必填,其他鍵不變
|
|
164
182
|
* Keep specified keys as Required, other keys unchanged
|
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 * \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 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';\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-type",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.12",
|
|
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",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"peerDependencies": {
|
|
98
98
|
"ts-toolbelt": "^9.6.0"
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "68144dcde64f5288df56b29573071d1583bc7087"
|
|
101
101
|
}
|