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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 提供提取物件成員(方法)的工具類型
|
|
6
6
|
* Provides utility types for extracting object members (methods)
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { ITSPickByType } from './pick-type';
|
|
9
9
|
import { ITSPropertyKey } from '../../type/base';
|
|
10
10
|
import { ITSExtractKeyof } from '../filter';
|
|
11
11
|
/**
|
|
@@ -21,7 +21,7 @@ import { ITSExtractKeyof } from '../filter';
|
|
|
21
21
|
* type Methods = ITSMemberMethods<User>;
|
|
22
22
|
* // type Methods = { greet(): void; fetch(): Promise<void>; }
|
|
23
23
|
*/
|
|
24
|
-
export type ITSMemberMethods<T> =
|
|
24
|
+
export type ITSMemberMethods<T> = ITSPickByType<T, Function, Extract<keyof T, ITSPropertyKey>>;
|
|
25
25
|
/**
|
|
26
26
|
* 取得物件方法的鍵
|
|
27
27
|
* Get keys of object methods
|
|
@@ -36,3 +36,133 @@ export type ITSMemberMethods<T> = ITSExtractRecord<T, Function, Extract<keyof T,
|
|
|
36
36
|
* // type MethodKeys = "greet" | "fetch"
|
|
37
37
|
*/
|
|
38
38
|
export type ITSKeyofMemberMethods<T> = ITSExtractKeyof<ITSMemberMethods<T>, ITSPropertyKey>;
|
|
39
|
+
/**
|
|
40
|
+
* 版本 12: 完全泛化版 - 支持任意鍵值類型與自定義條件
|
|
41
|
+
* 可配置:1) 值類型條件 2) 鍵排除列表 3) 輸出鍵類型
|
|
42
|
+
*
|
|
43
|
+
* ✅ 跨模組驗證:使用 infer 延遲類型解析,即使跨模組引用也能正確運作,
|
|
44
|
+
* 避免 IMethods 變為 string 的問題
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```
|
|
48
|
+
* type IMethods2 = "assert" | "clear" | "count" | "countReset" | "debug"
|
|
49
|
+
* | "dir" | "dirxml" | "error" | "group" | "groupCollapsed" | "groupEnd"
|
|
50
|
+
* | "info" | "log" | "table" | "time" | "timeEnd" | "timeLog" | "timeStamp"
|
|
51
|
+
* | "trace" | "warn" | "profile" | "profileEnd"
|
|
52
|
+
* export type IMethods2 = ITSExcludeFilterKeys<ITSExtractKeysV13<ITSMemberMethodsV12<Console, Function, 'constructor'>, string>, "Console" | 'new' | 'prototype' | 'Console' | 'length'>;
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* 類型參數:
|
|
56
|
+
* - T: 輸入對象類型(需 extends object)
|
|
57
|
+
* - ValueCond: 值類型條件(預設為函數類型 `(...args: any[]) => any`)
|
|
58
|
+
* - ExcludeKeys: 要排除的鍵列表(預設為 never,不排除任何鍵)
|
|
59
|
+
*
|
|
60
|
+
* 與 MemberMethodsV11 的差異:
|
|
61
|
+
* - V11: 固定排除函數類型的鍵,只能排除單個鍵
|
|
62
|
+
* - V12: 可自定義值類型條件(如只提取返回 Promise 的方法),支持排除多個鍵
|
|
63
|
+
*
|
|
64
|
+
* 核心機制:
|
|
65
|
+
* ---------------------------
|
|
66
|
+
* 1. 使用 `T extends infer U` 捕獲輸入類型,實現跨模組延遲解析
|
|
67
|
+
* 2. 映射類型遍歷所有鍵,篩選符合 ValueCond 的鍵
|
|
68
|
+
* 3. 若 ExcludeKeys 不為 never,使用 `as` 重映射排除指定鍵
|
|
69
|
+
*
|
|
70
|
+
* ✅ 跨模組驗證:使用 infer 延遲類型解析,即使跨模組引用也能正確運作,
|
|
71
|
+
* 避免 IMethods 變為 string 的問題
|
|
72
|
+
*
|
|
73
|
+
* 使用範例:
|
|
74
|
+
* ---------------------------
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* interface MyClass {
|
|
78
|
+
* name: string;
|
|
79
|
+
* log(): void;
|
|
80
|
+
* debug(): void;
|
|
81
|
+
* error(): void;
|
|
82
|
+
* constructor(): void;
|
|
83
|
+
* _privateMethod(): void;
|
|
84
|
+
* }
|
|
85
|
+
*
|
|
86
|
+
* // 1. 提取所有方法(預設行為,等同 MemberMethodsV11 無排除時)
|
|
87
|
+
* // ✅ 結果:'log' | 'debug' | 'error' | 'constructor' | '_privateMethod'
|
|
88
|
+
* type AllMethods = MemberMethodsV12<MyClass>;
|
|
89
|
+
*
|
|
90
|
+
* // 2. 提取方法但排除 constructor
|
|
91
|
+
* // ✅ 結果:'log' | 'debug' | 'error' | '_privateMethod'
|
|
92
|
+
* // ❌ 'constructor' 被排除
|
|
93
|
+
* type NoCtor = MemberMethodsV12<MyClass, (...args: any[]) => any, 'constructor'>;
|
|
94
|
+
*
|
|
95
|
+
* // 3. 排除多個鍵
|
|
96
|
+
* // ✅ 結果:'log' | 'debug' | 'error'
|
|
97
|
+
* // ❌ 'constructor'、'_privateMethod' 被排除
|
|
98
|
+
* type PublicMethods = MemberMethodsV12<MyClass, (...args: any[]) => any, 'constructor' | '_privateMethod'>;
|
|
99
|
+
*
|
|
100
|
+
* // 4. 自定義值類型條件 - 只提取返回 string 的方法
|
|
101
|
+
* interface StringReturnClass {
|
|
102
|
+
* getName(): string;
|
|
103
|
+
* getId(): number;
|
|
104
|
+
* log(): void;
|
|
105
|
+
* }
|
|
106
|
+
* // ✅ 結果:'getName'
|
|
107
|
+
* type StringMethods = MemberMethodsV12<StringReturnClass, () => string>;
|
|
108
|
+
*
|
|
109
|
+
* // 5. 自定義值類型 - 只提取返回 Promise 的方法
|
|
110
|
+
* interface AsyncClass {
|
|
111
|
+
* fetchData(): Promise<string>;
|
|
112
|
+
* syncMethod(): string;
|
|
113
|
+
* save(): Promise<void>;
|
|
114
|
+
* }
|
|
115
|
+
* // ✅ 結果:'fetchData' | 'save'
|
|
116
|
+
* type AsyncMethods = MemberMethodsV12<AsyncClass, () => Promise<any>>;
|
|
117
|
+
*
|
|
118
|
+
* // 6. 泛型類別中使用
|
|
119
|
+
* class GenericService<T> {
|
|
120
|
+
* data: T;
|
|
121
|
+
* fetch(): Promise<T>;
|
|
122
|
+
* save(): Promise<void>;
|
|
123
|
+
* private internal(): void;
|
|
124
|
+
* }
|
|
125
|
+
* // ✅ 結果:'fetch' | 'save' | 'internal'(含私有方法)
|
|
126
|
+
* // ❌ 'data' 被過濾(不是函數)
|
|
127
|
+
* type ServiceMethods = MemberMethodsV12<GenericService<any>>;
|
|
128
|
+
* // ✅ 結果:'fetch' | 'save'
|
|
129
|
+
* // ❌ 'internal' 也被排除(假設要排除私有方法)
|
|
130
|
+
* type PublicServiceMethods = MemberMethodsV12<GenericService<any>, (...args: any[]) => any, 'internal'>;
|
|
131
|
+
*
|
|
132
|
+
* // 7. 與 ExtractKeyofV12 組合使用 - 提取並轉換為 string 類型
|
|
133
|
+
* type MyClassMethods = MemberMethodsV12<MyClass>;
|
|
134
|
+
* type StringMethodKeys = ExtractKeyofV12<MyClassMethods, string>; // 'log' | 'debug' | 'error' | ...
|
|
135
|
+
*
|
|
136
|
+
* // 8. 內化排除模式 - 最簡潔用法
|
|
137
|
+
* // 將所有排除邏輯集中在 MemberMethodsV12 的 ExcludeKeys 參數中
|
|
138
|
+
* type CleanMethods = MemberMethodsV12<
|
|
139
|
+
* MyClass,
|
|
140
|
+
* Function,
|
|
141
|
+
* 'constructor' | 'new' | 'prototype' | '_privateMethod'
|
|
142
|
+
* >;
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* 進階組合範例:
|
|
146
|
+
* ---------------------------
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // 組合 FilterKeys 實現分階段過濾
|
|
150
|
+
* type Stage1 = MemberMethodsV12<ApiA>; // 提取 A 的方法
|
|
151
|
+
* type Stage2 = MemberMethodsV12<ApiB>; // 提取 B 的方法
|
|
152
|
+
* type Combined = FilterKeys<Stage1 | Stage2, 'constructor' | 'init'>;
|
|
153
|
+
*
|
|
154
|
+
* // 條件化排除
|
|
155
|
+
* type ConditionalMethods<T, ExcludePrivate extends boolean> =
|
|
156
|
+
* ExcludePrivate extends true
|
|
157
|
+
* ? MemberMethodsV12<T, (...args: any[]) => any, `_${string}`>
|
|
158
|
+
* : MemberMethodsV12<T>;
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @see ITSExcludeFilterKeys
|
|
162
|
+
* @see ITSExtractKeysV13
|
|
163
|
+
*/
|
|
164
|
+
export type ITSMemberMethodsV12<T, ValueCond = (...args: any[]) => any, ExcludeKeys extends PropertyKey = never> = T extends infer U ? U extends object ? ExcludeKeys extends never ? {
|
|
165
|
+
[K in keyof U]: U[K] extends ValueCond ? K : never;
|
|
166
|
+
}[keyof U] : {
|
|
167
|
+
[K in keyof U as U[K] extends ValueCond ? K extends ExcludeKeys ? never : K : never]: any;
|
|
168
|
+
} extends infer M ? keyof M : never : never : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"member.js","sourceRoot":"","sources":["member.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄成員工具\n * Record Member Utilities\n
|
|
1
|
+
{"version":3,"file":"member.js","sourceRoot":"","sources":["member.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄成員工具\n * Record Member Utilities\n *\n * 提供提取物件成員(方法)的工具類型\n * Provides utility types for extracting object members (methods)\n */\n\nimport { ITSExtractRecord, ITSPickByType } from './pick-type';\nimport { ITSPropertyKey } from '../../type/base';\nimport { ITSExtractKeyof } from '../filter';\n\n/**\n * 過濾出所有成員是函數且鍵類型為字串或符號的屬性\n * Filter out all members that are functions and key types are string or symbol\n *\n * @example\n * class User {\n * name: string;\n * greet(): void;\n * async fetch(): Promise<void>;\n * }\n * type Methods = ITSMemberMethods<User>;\n * // type Methods = { greet(): void; fetch(): Promise<void>; }\n */\nexport type ITSMemberMethods<T> = ITSPickByType<T, Function, Extract<keyof T, ITSPropertyKey>>;\n\n/**\n * 取得物件方法的鍵\n * Get keys of object methods\n *\n * @example\n * class User {\n * name: string;\n * greet(): void;\n * async fetch(): Promise<void>;\n * }\n * type MethodKeys = ITSKeyofMemberMethods<User>;\n * // type MethodKeys = \"greet\" | \"fetch\"\n */\nexport type ITSKeyofMemberMethods<T> = ITSExtractKeyof<ITSMemberMethods<T>, ITSPropertyKey>;\n\n/**\n * 版本 12: 完全泛化版 - 支持任意鍵值類型與自定義條件\n * 可配置:1) 值類型條件 2) 鍵排除列表 3) 輸出鍵類型\n *\n * ✅ 跨模組驗證:使用 infer 延遲類型解析,即使跨模組引用也能正確運作,\n * 避免 IMethods 變為 string 的問題\n *\n * @example\n * ```\n * type IMethods2 = \"assert\" | \"clear\" | \"count\" | \"countReset\" | \"debug\"\n * | \"dir\" | \"dirxml\" | \"error\" | \"group\" | \"groupCollapsed\" | \"groupEnd\"\n * | \"info\" | \"log\" | \"table\" | \"time\" | \"timeEnd\" | \"timeLog\" | \"timeStamp\"\n * | \"trace\" | \"warn\" | \"profile\" | \"profileEnd\"\n * export type IMethods2 = ITSExcludeFilterKeys<ITSExtractKeysV13<ITSMemberMethodsV12<Console, Function, 'constructor'>, string>, \"Console\" | 'new' | 'prototype' | 'Console' | 'length'>;\n * ```\n *\n * 類型參數:\n * - T: 輸入對象類型(需 extends object)\n * - ValueCond: 值類型條件(預設為函數類型 `(...args: any[]) => any`)\n * - ExcludeKeys: 要排除的鍵列表(預設為 never,不排除任何鍵)\n *\n * 與 MemberMethodsV11 的差異:\n * - V11: 固定排除函數類型的鍵,只能排除單個鍵\n * - V12: 可自定義值類型條件(如只提取返回 Promise 的方法),支持排除多個鍵\n *\n * 核心機制:\n * ---------------------------\n * 1. 使用 `T extends infer U` 捕獲輸入類型,實現跨模組延遲解析\n * 2. 映射類型遍歷所有鍵,篩選符合 ValueCond 的鍵\n * 3. 若 ExcludeKeys 不為 never,使用 `as` 重映射排除指定鍵\n *\n * ✅ 跨模組驗證:使用 infer 延遲類型解析,即使跨模組引用也能正確運作,\n * 避免 IMethods 變為 string 的問題\n *\n * 使用範例:\n * ---------------------------\n * @example\n * ```typescript\n * interface MyClass {\n * name: string;\n * log(): void;\n * debug(): void;\n * error(): void;\n * constructor(): void;\n * _privateMethod(): void;\n * }\n *\n * // 1. 提取所有方法(預設行為,等同 MemberMethodsV11 無排除時)\n * // ✅ 結果:'log' | 'debug' | 'error' | 'constructor' | '_privateMethod'\n * type AllMethods = MemberMethodsV12<MyClass>;\n *\n * // 2. 提取方法但排除 constructor\n * // ✅ 結果:'log' | 'debug' | 'error' | '_privateMethod'\n * // ❌ 'constructor' 被排除\n * type NoCtor = MemberMethodsV12<MyClass, (...args: any[]) => any, 'constructor'>;\n *\n * // 3. 排除多個鍵\n * // ✅ 結果:'log' | 'debug' | 'error'\n * // ❌ 'constructor'、'_privateMethod' 被排除\n * type PublicMethods = MemberMethodsV12<MyClass, (...args: any[]) => any, 'constructor' | '_privateMethod'>;\n *\n * // 4. 自定義值類型條件 - 只提取返回 string 的方法\n * interface StringReturnClass {\n * getName(): string;\n * getId(): number;\n * log(): void;\n * }\n * // ✅ 結果:'getName'\n * type StringMethods = MemberMethodsV12<StringReturnClass, () => string>;\n *\n * // 5. 自定義值類型 - 只提取返回 Promise 的方法\n * interface AsyncClass {\n * fetchData(): Promise<string>;\n * syncMethod(): string;\n * save(): Promise<void>;\n * }\n * // ✅ 結果:'fetchData' | 'save'\n * type AsyncMethods = MemberMethodsV12<AsyncClass, () => Promise<any>>;\n *\n * // 6. 泛型類別中使用\n * class GenericService<T> {\n * data: T;\n * fetch(): Promise<T>;\n * save(): Promise<void>;\n * private internal(): void;\n * }\n * // ✅ 結果:'fetch' | 'save' | 'internal'(含私有方法)\n * // ❌ 'data' 被過濾(不是函數)\n * type ServiceMethods = MemberMethodsV12<GenericService<any>>;\n * // ✅ 結果:'fetch' | 'save'\n * // ❌ 'internal' 也被排除(假設要排除私有方法)\n * type PublicServiceMethods = MemberMethodsV12<GenericService<any>, (...args: any[]) => any, 'internal'>;\n *\n * // 7. 與 ExtractKeyofV12 組合使用 - 提取並轉換為 string 類型\n * type MyClassMethods = MemberMethodsV12<MyClass>;\n * type StringMethodKeys = ExtractKeyofV12<MyClassMethods, string>; // 'log' | 'debug' | 'error' | ...\n *\n * // 8. 內化排除模式 - 最簡潔用法\n * // 將所有排除邏輯集中在 MemberMethodsV12 的 ExcludeKeys 參數中\n * type CleanMethods = MemberMethodsV12<\n * MyClass,\n * Function,\n * 'constructor' | 'new' | 'prototype' | '_privateMethod'\n * >;\n * ```\n *\n * 進階組合範例:\n * ---------------------------\n * @example\n * ```typescript\n * // 組合 FilterKeys 實現分階段過濾\n * type Stage1 = MemberMethodsV12<ApiA>; // 提取 A 的方法\n * type Stage2 = MemberMethodsV12<ApiB>; // 提取 B 的方法\n * type Combined = FilterKeys<Stage1 | Stage2, 'constructor' | 'init'>;\n *\n * // 條件化排除\n * type ConditionalMethods<T, ExcludePrivate extends boolean> =\n * ExcludePrivate extends true\n * ? MemberMethodsV12<T, (...args: any[]) => any, `_${string}`>\n * : MemberMethodsV12<T>;\n * ```\n *\n * @see ITSExcludeFilterKeys\n * @see ITSExtractKeysV13\n */\nexport type ITSMemberMethodsV12<\n\tT,\n\tValueCond = (...args: any[]) => any,\n\tExcludeKeys extends PropertyKey = never\n>\t// 1. T extends infer U - 使用 infer 捕獲輸入類型,實現延遲解析\n\t= T extends infer U\n\t// 2. U extends object - 確保輸入是對象類型(可遍歷鍵)\n\t? U extends object\n\t\t// 3. ExcludeKeys extends never - 檢查是否需要排除特定鍵\n\t\t? ExcludeKeys extends never\n\t\t\t// 3a. 無需排除 - 使用基本映射類型遍歷所有鍵\n\t\t\t// 遍歷 U 的所有鍵 K,若值類型 U[K] 符合 ValueCond 則保留 K,否則設為 never\n\t\t\t? { [K in keyof U]: U[K] extends ValueCond ? K : never; }[keyof U]\n\t\t\t// 3b. 需要排除 - 使用「as」重映射語法進行鍵過濾\n\t\t\t// 邏輯:先檢查值類型是否符合 ValueCond,再檢查鍵是否在 ExcludeKeys 中\n\t\t\t: {\n\t\t\t\t[K in keyof U as U[K] extends ValueCond\n\t\t\t\t\t// 若值符合條件,進一步檢查鍵是否需要排除\n\t\t\t\t\t? K extends ExcludeKeys ? never : K // 在排除列表中則設為 never,否則保留 K\n\t\t\t\t\t// 若值不符合條件,設為 never(過濾掉)\n\t\t\t\t\t: never]: any\n\t\t\t} extends infer M ? keyof M : never\n\t\t// U 不是 object,返回 never(無法提取方法)\n\t\t: never\n\t// T 無法解析為 infer U,返回 never\n\t: never;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit-index.js","sourceRoot":"","sources":["omit-index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 索引簽名移除工具\n * Index Signature Removal Utilities\n
|
|
1
|
+
{"version":3,"file":"omit-index.js","sourceRoot":"","sources":["omit-index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 索引簽名移除工具\n * Index Signature Removal Utilities\n *\n * 提供移除物件索引簽名的工具類型\n * Provides utility types for removing object index signatures\n */\n\n/**\n * 移除索引簽名\n * Remove index signature\n *\n * 從物件類型中移除索引簽名,保留明確宣告的鍵\n * Removes index signature from object type, keeping explicitly declared keys\n *\n * @see https://stackoverflow.com/a/51956054/4563339\n *\n * @example\n * interface WithIndex {\n * name: string;\n * [key: string]: any;\n * }\n * type WithoutIndex = ITSOmitIndexSignatures<WithIndex>;\n * // type WithoutIndex = { name: string }\n */\nexport type ITSOmitIndexSignatures<T extends Record<any, any>> = {\n\t[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]\n};\n\n/**\n * 取得已知的鍵(排除索引簽名)\n * Get known keys (excluding index signature)\n *\n * @example\n * interface WithIndex {\n * name: string;\n * [key: string]: any;\n * }\n * type Keys = ITSKnownKeys<WithIndex>;\n * // type Keys = \"name\"\n */\nexport type ITSKnownKeys<T extends Record<any, any>> = keyof ITSOmitIndexSignatures<T>;\n\n/**\n * 取得已知的鍵(另一種實現)\n * Get known keys (alternative implementation)\n *\n * @example\n * interface WithIndex {\n * name: string;\n * age: number;\n * [key: string]: any;\n * }\n * type Keys = ITSKnownKeys2<WithIndex>;\n * // type Keys = \"name\" | \"age\"\n */\nexport type ITSKnownKeys2<T> = {\n\t[K in keyof T]: string extends K ? never : number extends K ? never : K\n} extends { [_ in keyof T]: infer U } ? U : never;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分鍵檢測工具\n * Record Partial Key Detection Utilities\n
|
|
1
|
+
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分鍵檢測工具\n * Record Partial Key Detection Utilities\n *\n * 提供檢測物件鍵是否為可選的工具類型\n * Provides utility types for detecting if object keys are optional\n */\n\n/**\n * 檢測鍵是否為物件的部分鍵(可選鍵)\n * Check if key is a partial key (optional key) of the record\n *\n * 如果排除指定鍵後的類型可以賦值給原始類型,則該鍵為可選鍵\n * If the type after excluding the specified key is assignable to the original type, the key is optional\n *\n * @example\n * interface User {\n * name: string;\n * age?: number;\n * }\n * type PartialKeys = ITSKeyIsPartialOfRecord<User, 'age'>;\n * // type PartialKeys = \"age\"\n *\n * @example\n * interface User {\n * name: string;\n * age: number;\n * }\n * type PartialKeys = ITSKeyIsPartialOfRecord<User, 'age'>;\n * // type PartialKeys = never\n */\nexport type ITSKeyIsPartialOfRecord<T, K extends keyof T> = Omit<T, K> extends T ? K : never;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick-type.js","sourceRoot":"","sources":["pick-type.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nimport { ITSNullPrimitive } from '../../type/base';\nimport { ITSValueOf } from '../key-value';\nimport { ITSExclude2, ITSExtract2 } from '../filter';\n\nexport type ITSKeyofByExtractType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = K extends keyof T
|
|
1
|
+
{"version":3,"file":"pick-type.js","sourceRoot":"","sources":["pick-type.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nimport { ITSNullPrimitive } from '../../type/base';\nimport { ITSValueOf } from '../key-value';\nimport { ITSExclude2, ITSExtract2 } from '../filter';\n\nexport type ITSKeyofByExtractType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = K extends keyof T\n\t? T[K] extends U ? K : never\n\t: never;\n\n/**\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nexport type ITSKeyofByExcludeType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = K extends keyof T\n\t? T[K] extends U ? never : K\n\t: never;\n\n/**\n * From `T`, pick a set of properties whose type are assignable to `U`.\n *\n * @example\ntype OmitBoolean = ITSPickByType<{\n name: string\n count: number\n isReadonly: boolean\n isEnable: boolean\n}, boolean>\n *\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nexport type ITSPickByType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = {\n\t[P in ITSKeyofByExtractType<T, U, K>]: T[P]\n}\n\n/**\n * From `T`, pick a set of properties whose type are not assignable to `U`.\n *\n * @example\ntype OmitBoolean = ITSOmitByType<{\n name: string\n count: number\n isReadonly: boolean\n isEnable: boolean\n}, boolean>\n *\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nexport type ITSOmitByType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = {\n\t[P in ITSKeyofByExcludeType<T, U, K>]: T[P]\n}\n\n/**\n * @internal\n */\nexport type ITSRecordExcludeToKey<Base, Type> = {\n\t[Key in keyof Base]: ITSExclude2<Base[Key], Type, Key>\n};\n/**\n * @internal\n */\nexport type ITSRecordExtractToKey<Base, Type> = {\n\t[Key in keyof Base]: ITSExtract2<Base[Key], Type, Key>\n};\n\nexport type ITSKeyOfRecordExcludeToKey<Base, Type> = ITSValueOf<ITSRecordExcludeToKey<Base, Type>>;\nexport type ITSKeyOfRecordExtractToKey<Base, Type> = ITSValueOf<ITSRecordExtractToKey<Base, Type>>;\n\nexport type ITSPickRecordType<Base, Type> = Pick<Base, ITSKeyOfRecordExtractToKey<Base, Type>>;\nexport type ITSOmitRecordType<Base, Type> = Pick<Base, ITSKeyOfRecordExcludeToKey<Base, Type>>;\n\n/**\n * @deprecated use `ITSPickByType<M, T, K>`\n */\nexport type ITSExtractRecord<M, T, K extends keyof M = keyof M> = ITSPickByType<M, T, K>\n\nexport type ITSExtractRecordNoNull<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: NonNullable<M[P]>;\n};\n\n/**\n * @deprecated use `ITSOmitByType<M, T, K>`\n */\nexport type ITSExcludeRecord<M, T, K extends keyof M = keyof M> = ITSOmitByType<M, T, K>;\n\nexport type ITSExcludeRecordNoNull<M, T, K extends keyof M = keyof M> = ITSOmitByType<M, ITSNullPrimitive, K>;\n\n/**\n * @deprecated use `ITSKeyofByExtractType<T, U, K>`\n */\nexport type ITSExtractKeyofRecord<M, T, K extends keyof M = keyof M> = ITSKeyofByExtractType<M, T, K>;\n\n/**\n * @deprecated use `ITSKeyofByExcludeType<M, T, K>`\n */\nexport type ITSExcludeKeyofRecord<M, T, K extends keyof M = keyof M> = ITSKeyofByExcludeType<M, T, K>;\n"]}
|
package/lib/helper/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 utility types for object key manipulation\n *\n * @see https://stackoverflow.com/a/55479659/4563339\n */\n\nexport type { ITSKeyIsPartialOfRecord } from './record/partial';\n\n/**\n * 取得物件的唯讀鍵集合\n * Get the readonly keys of an object\n *\n * 回傳一個由物件所有唯讀鍵組成的聯集類型\n * Returns a union type consisting of all readonly keys of the object\n *\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/5-extreme-readonly-keys/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/87\n *\n * @alias ITSGetReadonlyKeys\n *\n * @example\n * interface Todo {\n * readonly title: string\n * readonly description: string\n * completed: boolean\n * }\n * type Keys = ITSKeyOfRecordExtractReadonly<Todo>\n * // expected to be \"title\" | \"description\"\n */\nexport type ITSKeyOfRecordExtractReadonly<T> = {\n\t[K in keyof T]-?: (<U>() => U extends { -readonly [P in K]: T[K] }\n\t\t? 1\n\t\t: 2) extends (<U>() => U extends { [P in K]: T[K] } ? 1 : 2) ? never : K\n}[keyof T];\n\n/** 取得物件的唯讀鍵集合(別名)/ Get the readonly keys of an object (alias) */\nexport type { ITSKeyOfRecordExtractReadonly as ITSGetReadonlyKeys }\n\n/**\n * 取得物件的非唯讀鍵集合\n * Get the non-readonly keys of an object\n *\n * 回傳一個由物件所有可寫入鍵組成的聯集類型\n * Returns a union type consisting of all writable keys of the object\n *\n * @example\n * interface Todo {\n * readonly title: string\n * readonly description: string\n * completed: boolean\n * }\n * type Keys = ITSKeyOfRecordExcludeReadonly<Todo>\n * // expected to be \"completed\"\n */\nexport type ITSKeyOfRecordExcludeReadonly<T> = Exclude<keyof T, ITSKeyOfRecordExtractReadonly<T>>\n\n/**\n * 檢查指定鍵是否為物件的唯讀鍵\n * Check if the specified key is a readonly key of the object\n *\n * @example\n * interface Todo {\n * readonly title: string\n * completed: boolean\n * }\n * type IsReadonly = ITSKeyIsReadonlyOfRecord<Todo, 'title'>;\n * // type IsReadonly = \"title\"\n */\nexport type ITSKeyIsReadonlyOfRecord<T, K extends ITSKeyOfRecordExtractReadonly<T>> = Extract<K, ITSKeyOfRecordExtractReadonly<T>>;\n\n/**\n * 檢查指定鍵是否為物件的非唯讀鍵\n * Check if the specified key is a non-readonly key of the object\n *\n * @example\n * interface Todo {\n * readonly title: string\n * completed: boolean\n * }\n * type IsWritable = ITSKeyIsNotReadonlyOfRecord<Todo, 'completed'>;\n * // type IsWritable = \"completed\"\n */\nexport type ITSKeyIsNotReadonlyOfRecord<T, K extends ITSKeyOfRecordExcludeReadonly<T>> = Extract<K, ITSKeyOfRecordExcludeReadonly<T>>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer.js","sourceRoot":"","sources":["infer.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串類型推斷工具\n * String Type Inference Utilities\n
|
|
1
|
+
{"version":3,"file":"infer.js","sourceRoot":"","sources":["infer.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串類型推斷工具\n * String Type Inference Utilities\n *\n * 提供從字串字面量類型推斷基礎類型的工具\n * Provides utilities for inferring base types from string literal types\n */\n\nimport { ITSToStringLiteralAllowedType } from '../string';\n\n/**\n * 從字串推斷指定類型\n * Infer specified type from string\n *\n * 嘗試將字串字面量類型推斷為指定的基礎類型\n * Attempts to infer a specified base type from a string literal type\n *\n * @example\n * type Num = ITSStringInferToType<'123', number>;\n * // type Num = 123\n *\n * @example\n * type Bool = ITSStringInferToType<'true', boolean>;\n * // type Bool = true\n */\nexport type ITSStringInferToType<Str extends string, Type extends ITSToStringLiteralAllowedType, R = never> =\n\tStr extends `${infer U extends Type}`\n\t\t? U\n\t\t: R;\n\n/**\n * 從字串推斷數字類型\n * Infer number type from string\n *\n * @example\n * type Num = ITSStringInferToNumber<'123'>;\n * // type Num = 123\n */\nexport type ITSStringInferToNumber<Str extends string, R = never> = ITSStringInferToType<Str, number, R>\n\n/**\n * 從字串推斷布林類型\n * Infer boolean type from string\n *\n * @example\n * type Bool = ITSStringInferToBoolean<'true'>;\n * // type Bool = true\n */\nexport type ITSStringInferToBoolean<Str extends string, R = never> = ITSStringInferToType<Str, boolean, R>\n\n/**\n * 從字串推斷 null 類型\n * Infer null type from string\n *\n * @example\n * type Null = ITSStringInferToNull<'null'>;\n * // type Null = null\n */\nexport type ITSStringInferToNull<Str extends string, R = never> = ITSStringInferToType<Str, null, R>\n\n/**\n * 從字串推斷 undefined 類型\n * Infer undefined type from string\n *\n * @example\n * type Undefined = ITSStringInferToUndefined<'undefined'>;\n * // type Undefined = undefined\n */\nexport type ITSStringInferToUndefined<Str extends string, R = never> = ITSStringInferToType<Str, undefined, R>\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal-string.js","sourceRoot":"","sources":["literal-string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串大小寫轉換工具\n * String Case Conversion Utilities\n
|
|
1
|
+
{"version":3,"file":"literal-string.js","sourceRoot":"","sources":["literal-string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串大小寫轉換工具\n * String Case Conversion Utilities\n *\n * 提供字串命名字面量的大小寫轉換工具\n * Provides string naming literal case conversion utilities\n */\n\n/**\n * 將連字符命名字符串轉換為 PascalCase\n * Convert kebab-case string literal to PascalCase\n *\n * @see yargs\n *\n * @example\n * type Result = ITSPascalCase<'foo-bar'>;\n * // type Result = \"FooBar\"\n *\n * @example\n * type Result = ITSPascalCase<'foo-bar-baz'>;\n * // type Result = \"FooBarBaz\"\n */\nexport type ITSPascalCase<S extends string> = string extends S\n\t? string\n\t: S extends `${infer T}-${infer U}`\n\t\t? `${Capitalize<T>}${ITSPascalCase<U>}`\n\t\t: Capitalize<S>;\n\n/**\n * 將連字符命名字符串轉換為 camelCase\n * Convert kebab-case string literal to camelCase\n *\n * @see yargs\n *\n * @example\n * type Result = ITSCamelCase<'foo-bar'>;\n * // type Result = \"fooBar\"\n *\n * @example\n * type Result = ITSCamelCase<'foo-bar-baz'>;\n * // type Result = \"fooBarBaz\"\n */\nexport type ITSCamelCase<S extends string> = string extends S\n\t? string\n\t: S extends `${infer T}-${infer U}`\n\t\t? `${T}${ITSPascalCase<U>}`\n\t\t: S;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.js","sourceRoot":"","sources":["operations.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串操作工具\n * String Operation Utilities\n
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["operations.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串操作工具\n * String Operation Utilities\n *\n * 提供字串相關的類型操作工具\n * Provides string-related type manipulation utilities\n */\n\n/**\n * 字串首字母大寫\n * Capitalize first letter of string\n *\n * @example\n * type Result = ITSCapitalize<'hello'>; // 'Hello'\n * type Result2 = ITSCapitalize<'world'>; // 'World'\n */\nexport type ITSCapitalize<S extends string> = S extends `${infer First}${infer Rest}`\n\t? `${Uppercase<First>}${Rest}`\n\t: S;\n\n/**\n * 字串首字母小寫\n * Uncapitalize first letter of string\n *\n * @example\n * type Result = ITSUncapitalize<'Hello'>; // 'hello'\n * type Result2 = ITSUncapitalize<'World'>; // 'world'\n */\nexport type ITSUncapitalize<S extends string> = S extends `${infer First}${infer Rest}`\n\t? `${Lowercase<First>}${Rest}`\n\t: S;\n\n/**\n * 字串轉為大寫\n * Convert string to uppercase\n *\n * @example\n * type Result = ITSToUpperCase<'hello'>; // 'HELLO'\n * type Result2 = ITSToUpperCase<'World'>; // 'WORLD'\n */\nexport type ITSToUpperCase<S extends string> = Uppercase<S>;\n\n/**\n * 字串轉為小寫\n * Convert string to lowercase\n *\n * @example\n * type Result = ITSToLowerCase<'HELLO'>; // 'hello'\n * type Result2 = ITSToLowerCase<'World'>; // 'world'\n */\nexport type ITSToLowerCase<S extends string> = Lowercase<S>;\n\n/**\n * TODO: 字串重複指定次數 - 無法實現\n * Repeat string specified number of times\n *\n * TypeScript 無法在類型層級進行遞迴數學運算\n * TypeScript cannot perform recursive mathematical operations at type level\n *\n * @example\n * type Result = ITSRepeat<'abc', 3>; // 'abcabcabc'\n * type Result2 = ITSRepeat<'x', 5>; // 'xxxxx'\n */\n// export type ITSRepeat<S extends string, N extends number> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSRepeat<S extends string, N extends number> = \n// \tN extends 0 \n// \t\t? '' \n// \t\t: N extends infer Count \n// \t\t\t? Count extends number \n// \t\t\t\t? `${S}${ITSRepeat<S, Count extends 0 ? never : Count - 1>}`\n// \t\t\t\t: never \n// \t\t\t: never;\n\n/**\n * TODO: 字串長度 - 無法實現\n * Get string length\n *\n * TypeScript 無法在類型層級計算字串長度\n * TypeScript cannot calculate string length at type level\n *\n * @example\n * type Result = ITSStringLength<'hello'>; // 5\n * type Result2 = ITSStringLength<''>; // 0\n */\n// export type ITSStringLength<S extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSStringLength<S extends string, Counter extends any[] = []> = \n// \tS extends `${string}${infer Rest}` \n// \t\t? ITSStringLength<Rest, [...Counter, any]>\n// \t\t: Counter['length'];\n\n/**\n * TODO: 字串分割 - 無法實現\n * Split string by separator\n *\n * TypeScript 無法在類型層級進行字串分割操作\n * TypeScript cannot perform string splitting operations at type level\n *\n * @example\n * type Result = ITSSplit<'a,b,c', ','>; // ['a', 'b', 'c']\n * type Result2 = ITSSplit<'hello world', ' '>; // ['hello', 'world']\n */\n// export type ITSSplit<S extends string, Separator extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSSplit<S extends string, Separator extends string> = \n// \tS extends `${infer First}${Separator}${infer Rest}`\n// \t\t? [First, ...ITSSplit<Rest, Separator>]\n// \t\t: [S];\n\n/**\n * TODO: 字串連接 - 無法實現\n * Join string array with separator\n *\n * TypeScript 無法在類型層級進行陣列連接操作\n * TypeScript cannot perform array joining operations at type level\n *\n * @example\n * type Result = ITSJoin<['a', 'b', 'c'], ','>; // 'a,b,c'\n * type Result2 = ITSJoin<['hello', 'world'], ' '>; // 'hello world'\n */\n// export type ITSJoin<T extends string[], Separator extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSJoin<T extends string[], Separator extends string> = \n// \tT extends [infer First, ...infer Rest]\n// \t\t? First extends string\n// \t\t\t? Rest extends string[]\n// \t\t\t\t? Rest['length'] extends 0\n// \t\t\t\t\t? First\n// \t\t\t\t\t: `${First}${Separator}${ITSJoin<Rest, Separator>}`\n// \t\t\t\t: never\n// \t\t\t: never\n// \t\t: '';\n\n/**\n * 字串替換\n * Replace substring in string\n *\n * @example\n * type Result = ITSReplace<'hello world', 'world', 'typescript'>; // 'hello typescript'\n * type Result2 = ITSReplace<'abc123', '123', '456'>; // 'abc456'\n */\nexport type ITSReplace<S extends string, Search extends string, Replace extends string> =\n\tS extends `${infer Prefix}${Search}${infer Suffix}`\n\t\t? `${Prefix}${Replace}${Suffix}`\n\t\t: S;\n\n/**\n * 字串是否包含子字串\n * Check if string contains substring\n *\n * @example\n * type Result = ITSIncludes<'hello world', 'world'>; // true\n * type Result2 = ITSIncludes<'hello world', 'typescript'>; // false\n */\nexport type ITSIncludes<S extends string, Search extends string> =\n\tS extends `${string}${Search}${string}` ? true : false;\n\n/**\n * 字串是否以指定前綴開始\n * Check if string starts with prefix\n *\n * @example\n * type Result = ITSStartsWith<'hello world', 'hello'>; // true\n * type Result2 = ITSStartsWith<'hello world', 'world'>; // false\n */\nexport type ITSStartsWith<S extends string, Prefix extends string> =\n\tS extends `${Prefix}${string}` ? true : false;\n\n/**\n * 字串是否以指定後綴結束\n * Check if string ends with suffix\n *\n * @example\n * type Result = ITSEndsWith<'hello world', 'world'>; // true\n * type Result2 = ITSEndsWith<'hello world', 'hello'>; // false\n */\nexport type ITSEndsWith<S extends string, Suffix extends string> =\n\tS extends `${string}${Suffix}` ? true : false;\n"]}
|
package/lib/helper/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字面量類型工具\n * Literal Type Utilities\n
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字面量類型工具\n * Literal Type Utilities\n *\n * 提供字串、數字、布林值轉換為字面量類型的工具\n * Provides utilities for converting strings, numbers, booleans to literal types\n */\n\n/** 允許轉換為字面量類型的基礎類型 / Base types allowed to convert to literal types */\nexport type ITSToStringLiteralAllowedType = string | number | boolean | bigint;\n\n/**\n * 將類型轉換為字面量類型 `${T}`\n * Convert type to literal type `${T}`\n *\n * @example\n * type Str = ITSToStringLiteral<'hello'>;\n * // type Str = \"hello\"\n *\n * @example\n * type Num = ITSToStringLiteral<42>;\n * // type Num = \"42\"\n */\nexport type ITSToStringLiteral<T extends ITSToStringLiteralAllowedType> = `${T}`\n\n/**\n * 原始類型與其字面量類型的聯合\n * Union of original type and its literal type\n *\n * T & `${T}`\n *\n * 適合用在 enum 或 string literal union,可以接受 enum 的字面量或基底類型\n * Suitable for enum or string literal union, can accept enum literal or base type\n *\n * @example\n * // 應用於 string literal union\n * type Status = 'active' | 'inactive' | 'pending';\n * type IStatus = ITSTypeAndStringLiteral<Status>;\n * // type IStatus = \"active\" | \"inactive\" | \"pending\" | string\n *\n * @example\n * // 應用於 enum\n * enum EnumPackageManager {\n * 'yarn' = 'yarn',\n * 'npm' = 'npm',\n * 'pnpm' = 'pnpm',\n * }\n * type IPackageManager = ITSTypeAndStringLiteral<EnumPackageManager>;\n * // type IPackageManager = EnumPackageManager | string\n *\n * @example\n * // 應用於 number,可接受數字或數字字串\n * type INumber = ITSTypeAndStringLiteral<number>;\n * // type INumber = number | `${number}`\n */\nexport type ITSTypeAndStringLiteral<T extends ITSToStringLiteralAllowedType> = T | ITSToStringLiteral<T>\n\n/**\n * 原始類型 S 與 T 的字面量類型的聯合\n * Union of original type S and literal type of T\n *\n * S & `${T}`\n *\n * @example\n * type Result = ITSAndStringLiteral<1 | 2 | 3, number>;\n * // type Result = number | \"1\" | \"2\" | \"3\"\n */\nexport type ITSAndStringLiteral<T extends ITSToStringLiteralAllowedType, S = string> = S | ITSToStringLiteral<T>\n\n/**\n * 原始類型 S、T 與 T 的字面量類型的聯合\n * Union of original types S, T and literal type of T\n *\n * S & T & `${T}`\n *\n * @example\n * type Result = ITSAndTypeAndStringLiteral<1 | 2 | 3, number>;\n * // type Result = number | \"1\" | \"2\" | \"3\"\n */\nexport type ITSAndTypeAndStringLiteral<T extends ITSToStringLiteralAllowedType, S = string> =\n\tS\n\t| ITSTypeAndStringLiteral<T>\n"]}
|
package/lib/helper/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["tuple.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 元組類型工具\n * Tuple Type Utilities\n
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["tuple.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 元組類型工具\n * Tuple Type Utilities\n *\n * 提供元組相關的類型操作工具\n * Provides tuple-related type manipulation utilities\n */\n\n/**\n * 取得元組的數字索引鍵\n * Get numeric index keys of a tuple\n *\n * 回傳元組的所有數字索引(不包括陣列方法如 length、push 等)\n * Returns all numeric indices of the tuple (excluding array methods like length, push, etc.)\n *\n * @example\n * type Keys = ITSTupleKeys<[string, string, string]>;\n * // type Keys = \"0\" | \"1\" | \"2\"\n *\n * @see https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type\n */\nexport type ITSTupleKeys<T extends any[]> = Exclude<keyof T, keyof []>\n"]}
|
package/lib/helper/typeof.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeof.js","sourceRoot":"","sources":["typeof.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 類型推断工具\n * Type Inference Utilities\n
|
|
1
|
+
{"version":3,"file":"typeof.js","sourceRoot":"","sources":["typeof.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 類型推断工具\n * Type Inference Utilities\n *\n * 提供迭代器和其他類型相關的工具類型\n * Provides iterator and other type-related utility types\n *\n * Created by user on 2019/6/11.\n */\n\n/**\n * 迭代器類型\n * Iterator type\n *\n * 處理 Iterator 或 IteratorResult 類型,保留其原始結構\n * Handles Iterator or IteratorResult types, preserving their original structure\n *\n * @example\n * type LazyIterator = ITSIteratorLazy<Iterator<string>>;\n * // type LazyIterator = Iterator<string>\n */\nexport type ITSIteratorLazy<T extends Iterator<any> | IteratorResult<any>> =\n\tT extends IteratorResult<infer U> ? IteratorResult<U> :\n\t\tT extends Iterator<infer U> ? Iterator<U> :\n\t\t\tT\n\t;\n\n/**\n * 取得迭代器的值類型\n * Get the value type of an iterator\n *\n * 從 Iterator 或 IteratorResult 類型中提取值類型\n * Extracts the value type from Iterator or IteratorResult types\n *\n * @see https://stackoverflow.com/questions/49285864/is-there-a-valueof-similar-to-keyof-in-typescript\n *\n * @example\n * type IteratorValue = ITSTypeOfIterator<Iterator<string>>;\n * // type IteratorValue = string\n *\n * @example\n * type IteratorResultValue = ITSTypeOfIterator<IteratorResult<number>>;\n * // type IteratorResultValue = number\n */\nexport type ITSTypeOfIterator<T extends ITSIteratorLazy<any>> =\n\tT extends Iterator<infer U> ? U :\n\t\tT extends IteratorResult<infer U> ? U :\n\t\t\tany\n\t;\n"]}
|
package/lib/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["helper.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSArrayListMaybeReadonly } from './type/base';\nimport { ITSAwaitedReturnType } from './helper/promise';\n\n
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["helper.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSArrayListMaybeReadonly } from './type/base';\nimport { ITSAwaitedReturnType } from './helper/promise';\n\n/**\n * 複製當前函數的參數並返回新的值類型\n * Copy current function with Parameters and return to new value\n *\n * 不支援函數重載\n * Not support overload\n *\n * @example\n * declare function f(a: number): number\n * declare let c: ITSOverwriteReturnType<typeof f, string>;\n * // c = (a: number) => string\n */\nexport type ITSOverwriteReturnType<T extends (...args: any[]) => any, R extends unknown> =\n\t(...args: Parameters<T>) => R;\n\n/**\n * 將函數包裝為返回 PromiseLike 的版本\n * Wrap function to return PromiseLike version\n */\nexport type ITSWrapFunctionPromiseLike<T extends (...args: any[]) => any> =\n\t(...args: Parameters<T>) => PromiseLike<ITSAwaitedReturnType<T>>;\n/**\n * 將函數包裝為返回 Promise 的版本\n * Wrap function to return Promise version\n */\nexport type ITSWrapFunctionPromise<T extends (...args: any[]) => any> =\n\t(...args: Parameters<T>) => Promise<ITSAwaitedReturnType<T>>;\n\n/**\n * 擴展類型檢查:從 T 中提取屬於 U 的部分\n * Extend type check: extract parts of T that belong to U\n *\n * @deprecated 已棄用 / Deprecated\n */\nexport type ITSExtendsOf<T, U> = Extract<T, U>;\n\n/**\n * 取得陣列類型的數字索引鍵\n * Get numeric index keys of array type\n */\nexport type ITSKeyOfArray<T extends ITSArrayListMaybeReadonly<any>> = Exclude<keyof T, symbol | string>;\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["filter.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部過濾工具(內部使用)\n * Internal Filter Utilities (Internal Use)\n
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["filter.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部過濾工具(內部使用)\n * Internal Filter Utilities (Internal Use)\n *\n * 提供內部使用的過濾類型工具\n * Provides internal filter type utilities\n */\n\nimport { ITSExtract2 } from '../helper/filter';\n\n/**\n * 根據匹配鍵過濾記錄(內部使用)\n * Filter record by matching keys (internal use)\n *\n * @internal\n */\ntype I_RecordOfMatchKey<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: ITSExtract2<M[P], T, P>;\n};\n\n/**\n * 根據匹配值過濾記錄(內部使用)\n * Filter record by matching values (internal use)\n *\n * @internal\n */\ntype I_RecordOfMatchValue<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: ITSExtract2<M[P], T>;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-literal.js","sourceRoot":"","sources":["string-literal.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部字串字面量邏輯工具(內部使用)\n * Internal String Literal Logic Utilities (Internal Use)\n
|
|
1
|
+
{"version":3,"file":"string-literal.js","sourceRoot":"","sources":["string-literal.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部字串字面量邏輯工具(內部使用)\n * Internal String Literal Logic Utilities (Internal Use)\n *\n * 提供內部使用的字串字面量邏輯判斷工具\n * Provides internal string literal logic detection utilities\n */\n\n/**\n * 檢測 T 是否為聯合類型(內部使用)\n * Detect if T is a union type (internal use)\n *\n * @internal\n *\n * @example\n * type Test1 = IsAUnion<'a' | 'b'>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = IsAUnion<'a'>;\n * // type Test2 = false\n */\nexport type IsAUnion<T, Y = true, N = false, U = T> = U extends any\n\t? ([T] extends [U] ? N : Y)\n\t: never;\n\n/**\n * 檢測 T 是否為單一字串字面量(內部使用)\n * Detect if T is a single string literal (internal use)\n *\n * @internal\n *\n * @example\n * type Test1 = IsASingleStringLiteral<'hello'>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = IsASingleStringLiteral<'a' | 'b'>;\n * // type Test2 = false\n *\n * @example\n * type Test3 = IsASingleStringLiteral<string>;\n * // type Test3 = false\n */\nexport type IsASingleStringLiteral<\n\tT extends string,\n\tY = true,\n\tN = false\n> = string extends T ? N : [T] extends [never] ? N : IsAUnion<T, N, Y>;\n"]}
|
package/lib/logic/any.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"any.js","sourceRoot":"","sources":["any.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Any 類型判斷工具\n * Any Type Detection Utilities\n
|
|
1
|
+
{"version":3,"file":"any.js","sourceRoot":"","sources":["any.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Any 類型判斷工具\n * Any Type Detection Utilities\n *\n * 提供檢測類型是否為 any 的工具\n * Provides utilities for detecting if a type is any\n *\n * @see https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360\n */\n\n/**\n * 檢測類型是否為 any\n * Detect if a type is any\n *\n * 利用 any 與任何類型交叉都會得到 any 的特性來檢測\n * Uses the fact that any intersected with any type still results in any\n *\n * @example\n * type Test1 = ITSLogicIsAny<any>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = ITSLogicIsAny<string>;\n * // type Test2 = false\n */\nexport type ITSLogicIsAny<T, Y = true, N = false> = 0 extends (1 & T) ? Y : N\n\n/**\n * 檢測類型是否不為 any\n * Detect if a type is not any\n *\n * @example\n * type Test1 = ITSLogicNotAny<any>;\n * // type Test1 = false\n *\n * @example\n * type Test2 = ITSLogicNotAny<string>;\n * // type Test2 = true\n */\nexport type ITSLogicNotAny<T, Y = true, N = false> = ITSLogicIsAny<T, N, Y>\n"]}
|
package/lib/logic/never.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"never.js","sourceRoot":"","sources":["never.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Never 類型判斷工具\n * Never Type Detection Utilities\n
|
|
1
|
+
{"version":3,"file":"never.js","sourceRoot":"","sources":["never.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Never 類型判斷工具\n * Never Type Detection Utilities\n *\n * 提供檢測類型是否為 never 的工具\n * Provides utilities for detecting if a type is never\n */\n\n/**\n * 檢測類型是否為 never\n * Detect if a type is never\n *\n * 利用 never 是所有類型的子類型特性來檢測\n * Uses the fact that never is a subtype of all types\n *\n * @example\n * type Test1 = ITSLogicIsNever<never>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = ITSLogicIsNever<string>;\n * // type Test2 = false\n */\nexport type ITSLogicIsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSEmptyRecord } from '../../type/record/empty';\n\nexport type ITSLogicIsEmptyRecord<T, Y = true, N = false> = T extends ITSEmptyRecord ? Y : N\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 聯合類型邏輯工具\n * Union Type Logic Utilities\n
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 聯合類型邏輯工具\n * Union Type Logic Utilities\n *\n * 提供聯合類型相關的邏輯判斷工具\n * Provides union type-related logic detection utilities\n */\n\nimport { ITSUnionToIntersection } from '../../helper/intersection';\nimport { ITSLogicIsNever } from '../never';\n\n/**\n * 檢測類型是否為聯合類型\n * Detect if a type is a union type\n *\n * @example\n * type Test1 = ITSLogicIsUnion<string | number>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = ITSLogicIsUnion<string>;\n * // type Test2 = false\n */\nexport type ITSLogicIsUnion<T, Y = true, N = false> = [T] extends [ITSUnionToIntersection<T>] ? N : Y\n\n/**\n * 檢測類型是否為單一非聯合類型\n * Detect if a type is a single non-union type\n *\n * @see https://stackoverflow.com/a/49982981/4563339\n *\n * @example\n * type Test1 = ITSLogicIsSingleNonUnion01<'' | '4' | any, string>;\n * // type Test1 = false (因為是聯合類型)\n *\n * @example\n * type Test2 = ITSLogicIsSingleNonUnion01<'' & '4' & any, string>;\n * // type Test2 = false (因為是交集類型)\n *\n * @example\n * type Test3 = ITSLogicIsSingleNonUnion01<'', string>;\n * // type Test3 = true (因為是單一類型)\n */\nexport type ITSLogicIsSingleNonUnion01<\n\tT,\n\tU extends any,\n\tY = true,\n\tN = false\n> = U extends T ?\n\tN : ITSLogicIsNever<T, N, ITSLogicIsUnion<T, N, Y>>\n\t;\n"]}
|
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
|
|
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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["generator.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["generator.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * TypeScript Generator 類型\n * TypeScript Generator type\n *\n * 代表 JavaScript Generator 物件的類型\n * Represents the type of a JavaScript Generator object\n *\n * @typeParam T - 生成器yield的值類型 / Type of value yielded by the generator\n * @typeParam TReturn - 生成器完成時返回的類型 / Type returned when generator completes\n * @typeParam TNext - 傳遞給生成器next()方法的參數類型 / Type of argument passed to generator's next() method\n */\nexport type ITSGenerator<T = unknown, TReturn = T, TNext = T> = Generator<T, TReturn, TNext>;\n\n/**\n * TypeScript AsyncGenerator 類型\n * TypeScript AsyncGenerator type\n *\n * 代表 JavaScript AsyncGenerator 物件的類型\n * Represents the type of a JavaScript AsyncGenerator object\n *\n * @typeParam T - 生成器yield的值類型 / Type of value yielded by the async generator\n * @typeParam TReturn - 生成器完成時返回的類型 / Type returned when async generator completes\n * @typeParam TNext - 傳遞給生成器next()方法的參數類型 / Type of argument passed to async generator's next() method\n */\nexport type ITSAsyncGenerator<T = unknown, TReturn = T, TNext = T> = AsyncGenerator<T, TReturn, TNext>;\n"]}
|
package/lib/type/iterator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterator.js","sourceRoot":"","sources":["iterator.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 迭代器類型定義\n * Iterator Type Definitions\n
|
|
1
|
+
{"version":3,"file":"iterator.js","sourceRoot":"","sources":["iterator.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 迭代器類型定義\n * Iterator Type Definitions\n *\n * 提供 Iterator 和 IteratorResult 的類型定義\n * Provides Iterator and IteratorResult type definitions\n */\n\n/**\n * Iterator 類型\n * Iterator type\n *\n * @example\n * const iterator: ITSIterator<string> = {\n * next() { return { done: false, value: 'test' }; }\n * };\n */\nexport type ITSIterator<T, TReturn = void, TNext = undefined> = Iterator<T, TReturn, TNext>;\n\n/**\n * IteratorResult 類型\n * IteratorResult type\n *\n * @example\n * const result: ITSIteratorResult<string> = { done: false, value: 'test' };\n */\nexport type ITSIteratorResult<T, TReturn = void> = IteratorResult<T, TReturn>;\n"]}
|
package/lib/type/promise.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["promise.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Promise 類型工具\n * Promise Type Utilities\n
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["promise.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Promise 類型工具\n * Promise Type Utilities\n *\n * 提供 Promise 相關的類型操作工具\n * Provides Promise-related type manipulation utilities\n *\n * Created by user on 2019/6/11.\n */\n\n/**\n * 延遲物件類型:將物件的所有屬性包裝為 Promise\n * Deferred object type: wraps all properties of an object in Promise\n *\n * 保持相同的屬性名稱,但將值類型包裝為 Promise\n * Keeps the same property names, but wraps value types in Promise\n *\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html\n *\n * @example\n * interface User {\n * id: number;\n * name: string;\n * }\n * type DeferredUser = ITSDeferred<User>;\n * // type DeferredUser = { id: Promise<number>; name: Promise<string>; }\n */\nexport type ITSDeferred<T> = {\n\t[P in keyof T]: Promise<T[P]>;\n};\n\n/**\n * Promise 解決結果介面\n * Promise fulfilled result interface\n *\n * 表示 Promise 已成功解決\n * Represents a promise that has been successfully resolved\n *\n * @example\n * const fulfilled: ITSPromiseFulfilledResult<string> = {\n * status: \"fulfilled\",\n * value: \"success\"\n * };\n */\nexport interface ITSPromiseFulfilledResult<T>\n{\n\t/** 解決狀態 / Fulfilled status */\n\tstatus: \"fulfilled\";\n\t/** 解決值 / Resolved value */\n\tvalue: T;\n\t/** 永不存在的拒絕原因 / Reason that never exists */\n\treason?: never;\n}\n\n/**\n * Promise 拒絕結果介面\n * Promise rejected result interface\n *\n * 表示 Promise 被拒絕\n * Represents a promise that has been rejected\n *\n * @example\n * const rejected: ITSPromiseRejectedResult<Error> = {\n * status: \"rejected\",\n * reason: new Error(\"failed\")\n * };\n */\nexport interface ITSPromiseRejectedResult<E = any>\n{\n\t/** 拒絕狀態 / Rejected status */\n\tstatus: \"rejected\";\n\t/** 拒絕原因 / Rejection reason */\n\treason: E;\n\t/** 永不存在的解決值 / Value that never exists */\n\tvalue?: never;\n}\n\n/**\n * Promise settled 結果類型:解決或拒絕結果的聯合類型\n * Promise settled result type: union of fulfilled or rejected result\n *\n * @example\n * const result: ITSPromiseSettledResult<string> = Math.random() > 0.5\n * ? { status: \"fulfilled\", value: \"success\" }\n * : { status: \"rejected\", reason: new Error(\"failed\") };\n */\nexport type ITSPromiseSettledResult<T, E = any> = ITSPromiseFulfilledResult<T> | ITSPromiseRejectedResult<E>;\n"]}
|
package/lib/type/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["proxy.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Proxy 類型工具\n * Proxy Type Utilities\n
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["proxy.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Proxy 類型工具\n * Proxy Type Utilities\n *\n * 提供 Proxy 相關的類型操作工具\n * Provides Proxy-related type manipulation utilities\n */\n\n/**\n * 將物件的屬性包裝為 Proxy\n * Wrap properties of object with Proxy\n *\n * 將每個屬性轉換為具有 getter 和 setter 的物件\n * Converts each property to an object with getter and setter\n *\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html\n *\n * @example\n * interface User { name: string; age: number; }\n * type ProxifiedUser = ITSProxify<User>;\n * // type ProxifiedUser = {\n * // name: { get(): string; set(v: string): void };\n * // age: { get(): number; set(v: number): void };\n * // }\n */\nexport type ITSProxify<T> = {\n\t[P in keyof T]: { get(): T[P]; set(v: T[P]): void }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 空記錄類型工具\n * Empty Record Type Utilities\n
|
|
1
|
+
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 空記錄類型工具\n * Empty Record Type Utilities\n *\n * 提供空記錄類型的工具\n * Provides empty record type utilities\n *\n * @see https://juejin.cn/post/7116327095118069773\n */\n\n/**\n * 指定鍵集合的空記錄\n * Empty record with specified key set\n *\n * 建立一個具有指定鍵集合但所有值都為 never 的記錄類型\n * Creates a record type with specified key set but all values are never\n *\n * @example\n * type EmptyByKeys = ITSEmptyRecordByKeys<'a' | 'b'>;\n * // type EmptyByKeys = { a: never; b: never; }\n */\nexport type ITSEmptyRecordByKeys<K extends PropertyKey> = Record<K, never>;\n\n/**\n * 空記錄(接受任何鍵,但值都為 never)\n * Empty record (accepts any key, but values are never)\n *\n * @example\n * type Empty = ITSEmptyRecord;\n * // type Empty = Record<PropertyKey, never>\n *\n * @see https://juejin.cn/post/7116327095118069773\n */\nexport type ITSEmptyRecord = ITSEmptyRecordByKeys<PropertyKey>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["enum.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 列舉類型定義\n * Enum Type Definitions\n
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["enum.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 列舉類型定義\n * Enum Type Definitions\n *\n * 提供列舉類型的相關類型定義\n * Provides enum type related type definitions\n */\n\nimport { ITSReadonlyRecord } from './readonly';\nimport { ITSTypeAndStringLiteral } from '../../helper/string';\n\n/**\n * 列舉類型\n * Enum type\n *\n * 支援字串列舉、數字列舉或兩者的組合\n * Supports string enums, number enums, or a combination of both\n *\n * @example\n * // 字串列舉\n * enum EnumString { A = 'a', B = 'b' }\n * // 數字列舉\n * enum EnumNumber { A = 1, B = 2 }\n * // 混合列舉\n * enum EnumMixed { A = 'a', B = 1 }\n */\nexport type ITSEnumLike<K extends string = string, V extends string | number = string | number> =\n\tITSReadonlyRecord<K, V>\n\t| (V extends number ? ITSNumberEnumLikeReverse<K, Exclude<V, string>> : ITSEnumLikeReverseExcludeNumber);\n\n/**\n * 字串列舉類型\n * String enum type\n *\n * @example\n * enum EnumString { A = 'a', B = 'b' }\n * type T = ITSStringEnumLike<EnumString>;\n */\nexport type ITSStringEnumLike<K extends string = string, V extends string = string> =\n\t(ITSReadonlyRecord<K, V> | ITSStringEnumLikeReverse<K, V>)\n\t& ITSEnumLikeReverseExcludeNumber;\n\n/**\n * 數字列舉類型\n * Number enum type\n *\n * @example\n * enum EnumNumber { A = 1, B = 2 }\n * type T = ITSNumberEnumLike<EnumNumber>;\n */\nexport type ITSNumberEnumLike<K extends string = string, V extends number = number> =\n\tITSReadonlyRecord<K, V>\n\t| ITSNumberEnumLikeReverse<K, V>;\n\n/**\n * 字串列舉反向映射類型(內部使用)\n * String enum reverse mapping type (internal use)\n *\n * @internal\n */\nexport type ITSStringEnumLikeReverse<K extends string = string, V extends string = string> =\n\tITSReadonlyRecord<V, K>;\n\n/**\n * 數字列舉反向映射類型(內部使用)\n * Number enum reverse mapping type (internal use)\n *\n * @see https://github.com/microsoft/TypeScript/issues/51105\n *\n * @internal\n */\nexport type ITSNumberEnumLikeReverse<K extends string = string, V extends number = number> = ITSReadonlyRecord<Exclude<ITSTypeAndStringLiteral<V>, K>, K>;\n\n/**\n * 排除數字的列舉反向映射(內部使用)\n * Enum reverse mapping excluding number (internal use)\n *\n * @internal\n */\nexport type ITSEnumLikeReverseExcludeNumber = ITSReadonlyRecord<number, void | never>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分類型工具\n * Record Partial Type Utilities\n
|
|
1
|
+
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分類型工具\n * Record Partial Type Utilities\n *\n * 提供可選和必填記錄類型的工具\n * Provides optional and required record type utilities\n */\n\n/**\n * 可選的記錄類型\n * Optional record type\n *\n * 類似 Partial,但使用指定的鍵集合\n * Similar to Partial, but uses a specified key set\n *\n * @example\n * type PartialUser = ITSPartialRecord<'name' | 'age', string>;\n * // type PartialUser = { name?: string; age?: string; }\n */\nexport type ITSPartialRecord<K extends keyof any, T> = {\n\t[P in K]?: T;\n};\n\n/**\n * 必填的記錄類型\n * Required record type\n *\n * 類似 Required,但使用指定的鍵集合\n * Similar to Required, but uses a specified key set\n *\n * @example\n * type RequiredUser = ITSRequireRecord<'name' | 'age', string>;\n * // type RequiredUser = { name: string; age: string; }\n */\nexport type ITSRequireRecord<K extends keyof any, T> = {\n\t[P in K]-?: T;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄唯讀類型工具\n * Record Readonly Type Utilities\n
|
|
1
|
+
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄唯讀類型工具\n * Record Readonly Type Utilities\n *\n * 提供唯讀和可讀寫記錄類型的工具\n * Provides readonly and writable record type utilities\n */\n\n/**\n * 唯讀記錄類型\n * Readonly record type\n *\n * 將指定鍵集合的所有屬性設為唯讀\n * Makes all properties of the specified key set readonly\n *\n * @example\n * type ReadonlyUser = ITSReadonlyRecord<'name' | 'age', string>;\n * // type ReadonlyUser = { readonly name: string; readonly age: string; }\n */\nexport type ITSReadonlyRecord<K extends keyof any, T> = {\n\treadonly [P in K]: T;\n};\n\n/**\n * 可讀寫記錄類型\n * Writable record type\n *\n * 將指定鍵集合的所有屬性設為可讀寫(移除 readonly)\n * Makes all properties of the specified key set writable (removes readonly)\n *\n * @example\n * type WritableUser = ITSWriteableRecord<'name' | 'age', string>;\n * // type WritableUser = { name: string; age: string; }\n */\nexport type ITSWriteableRecord<K extends keyof any, T> = {\n\t-readonly [P in K]: T;\n};\n"]}
|