ts-type 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +43 -9
  3. package/docs/01-base-types.md +218 -0
  4. package/docs/02-built-in-types.md +200 -0
  5. package/docs/03-function-types.md +156 -0
  6. package/docs/04-promise-types.md +166 -0
  7. package/docs/05-array-tuple-types.md +159 -0
  8. package/docs/06-object-record-types.md +234 -0
  9. package/docs/07-string-number-types.md +325 -0
  10. package/docs/08-logic-types.md +154 -0
  11. package/docs/README.md +155 -0
  12. package/lib/_build-in.d.ts +56 -2
  13. package/lib/_build-in.js +7 -2
  14. package/lib/_build-in.js.map +1 -1
  15. package/lib/generic.d.ts +33 -0
  16. package/lib/generic.js.map +1 -1
  17. package/lib/helper/array/readonly.d.ts +16 -0
  18. package/lib/helper/array/readonly.js.map +1 -1
  19. package/lib/helper/filter.d.ts +62 -4
  20. package/lib/helper/filter.js.map +1 -1
  21. package/lib/helper/infer.d.ts +19 -0
  22. package/lib/helper/infer.js.map +1 -1
  23. package/lib/helper/intersection.d.ts +3 -0
  24. package/lib/helper/intersection.js.map +1 -1
  25. package/lib/helper/key-value.d.ts +90 -4
  26. package/lib/helper/key-value.js +5 -1
  27. package/lib/helper/key-value.js.map +1 -1
  28. package/lib/helper/number.d.ts +23 -0
  29. package/lib/helper/number.js.map +1 -1
  30. package/lib/helper/overwrite.d.ts +4 -0
  31. package/lib/helper/overwrite.js.map +1 -1
  32. package/lib/helper/promise.d.ts +8 -0
  33. package/lib/helper/promise.js.map +1 -1
  34. package/lib/helper/readonly.d.ts +114 -2
  35. package/lib/helper/readonly.js.map +1 -1
  36. package/lib/helper/record/enum.d.ts +43 -0
  37. package/lib/helper/record/enum.js +7 -0
  38. package/lib/helper/record/enum.js.map +1 -1
  39. package/lib/helper/record/member.d.ts +31 -1
  40. package/lib/helper/record/member.js +7 -0
  41. package/lib/helper/record/member.js.map +1 -1
  42. package/lib/helper/record/omit-index.d.ts +45 -1
  43. package/lib/helper/record/omit-index.js +7 -1
  44. package/lib/helper/record/omit-index.js.map +1 -1
  45. package/lib/helper/record/partial.d.ts +28 -1
  46. package/lib/helper/record/partial.js +7 -0
  47. package/lib/helper/record/partial.js.map +1 -1
  48. package/lib/helper/record.d.ts +56 -5
  49. package/lib/helper/record.js +7 -1
  50. package/lib/helper/record.js.map +1 -1
  51. package/lib/helper/string/infer.d.ts +54 -0
  52. package/lib/helper/string/infer.js +7 -0
  53. package/lib/helper/string/infer.js.map +1 -1
  54. package/lib/helper/string/literal-string.d.ts +29 -2
  55. package/lib/helper/string/literal-string.js +7 -0
  56. package/lib/helper/string/literal-string.js.map +1 -1
  57. package/lib/helper/string.d.ts +59 -1
  58. package/lib/helper/string.js +7 -0
  59. package/lib/helper/string.js.map +1 -1
  60. package/lib/helper/tuple.d.ts +15 -2
  61. package/lib/helper/tuple.js +7 -0
  62. package/lib/helper/tuple.js.map +1 -1
  63. package/lib/helper/typeof.d.ts +34 -0
  64. package/lib/helper/typeof.js +6 -0
  65. package/lib/helper/typeof.js.map +1 -1
  66. package/lib/helper.d.ts +20 -3
  67. package/lib/helper.js.map +1 -1
  68. package/lib/internal/filter.d.ts +7 -0
  69. package/lib/internal/filter.js +7 -0
  70. package/lib/internal/filter.js.map +1 -1
  71. package/lib/internal/logic/string-literal.d.ts +35 -2
  72. package/lib/internal/logic/string-literal.js +7 -0
  73. package/lib/internal/logic/string-literal.js.map +1 -1
  74. package/lib/logic/any.d.ts +33 -0
  75. package/lib/logic/any.js +9 -0
  76. package/lib/logic/any.js.map +1 -1
  77. package/lib/logic/never.d.ts +22 -0
  78. package/lib/logic/never.js +7 -0
  79. package/lib/logic/never.js.map +1 -1
  80. package/lib/logic/union/index.d.ts +32 -6
  81. package/lib/logic/union/index.js +7 -0
  82. package/lib/logic/union/index.js.map +1 -1
  83. package/lib/type/base.d.ts +77 -1
  84. package/lib/type/base.js +5 -1
  85. package/lib/type/base.js.map +1 -1
  86. package/lib/type/iterator.d.ts +23 -0
  87. package/lib/type/iterator.js +7 -0
  88. package/lib/type/iterator.js.map +1 -1
  89. package/lib/type/promise.d.ts +61 -1
  90. package/lib/type/promise.js +6 -0
  91. package/lib/type/promise.js.map +1 -1
  92. package/lib/type/proxy.d.ts +19 -2
  93. package/lib/type/proxy.js +5 -1
  94. package/lib/type/proxy.js.map +1 -1
  95. package/lib/type/record/empty.d.ts +24 -0
  96. package/lib/type/record/empty.js +9 -0
  97. package/lib/type/record/empty.js.map +1 -1
  98. package/lib/type/record/enum.d.ts +49 -1
  99. package/lib/type/record/enum.js +7 -0
  100. package/lib/type/record/enum.js.map +1 -1
  101. package/lib/type/record/partial.d.ts +29 -0
  102. package/lib/type/record/partial.js +7 -0
  103. package/lib/type/record/partial.js.map +1 -1
  104. package/lib/type/record/readonly.d.ts +29 -0
  105. package/lib/type/record/readonly.js +7 -0
  106. package/lib/type/record/readonly.js.map +1 -1
  107. package/lib/type/record.d.ts +137 -15
  108. package/lib/type/record.js +6 -0
  109. package/lib/type/record.js.map +1 -1
  110. package/lib/type/tuple/empty.d.ts +15 -0
  111. package/lib/type/tuple/empty.js +7 -0
  112. package/lib/type/tuple/empty.js.map +1 -1
  113. package/package.json +32 -17
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * 元組類型工具
4
+ * Tuple Type Utilities
5
+ *
6
+ * 提供元組相關的類型操作工具
7
+ * Provides tuple-related type manipulation utilities
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  //# sourceMappingURL=tuple.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tuple.js","sourceRoot":"","sources":["tuple.ts"],"names":[],"mappings":"","sourcesContent":["\n/**\n * get keys of tuple\n *\n * @example\n * ITSTupleKeys<[string, string, string]> = \"0\" | \"1\" | \"2\"\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"]}
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"]}
@@ -1,5 +1,39 @@
1
1
  /**
2
+ * 類型推断工具
3
+ * Type Inference Utilities
4
+ *
5
+ * 提供迭代器和其他類型相關的工具類型
6
+ * Provides iterator and other type-related utility types
7
+ *
2
8
  * Created by user on 2019/6/11.
3
9
  */
10
+ /**
11
+ * 迭代器類型
12
+ * Iterator type
13
+ *
14
+ * 處理 Iterator 或 IteratorResult 類型,保留其原始結構
15
+ * Handles Iterator or IteratorResult types, preserving their original structure
16
+ *
17
+ * @example
18
+ * type LazyIterator = ITSIteratorLazy<Iterator<string>>;
19
+ * // type LazyIterator = Iterator<string>
20
+ */
4
21
  export type ITSIteratorLazy<T extends Iterator<any> | IteratorResult<any>> = T extends IteratorResult<infer U> ? IteratorResult<U> : T extends Iterator<infer U> ? Iterator<U> : T;
22
+ /**
23
+ * 取得迭代器的值類型
24
+ * Get the value type of an iterator
25
+ *
26
+ * 從 Iterator 或 IteratorResult 類型中提取值類型
27
+ * Extracts the value type from Iterator or IteratorResult types
28
+ *
29
+ * @see https://stackoverflow.com/questions/49285864/is-there-a-valueof-similar-to-keyof-in-typescript
30
+ *
31
+ * @example
32
+ * type IteratorValue = ITSTypeOfIterator<Iterator<string>>;
33
+ * // type IteratorValue = string
34
+ *
35
+ * @example
36
+ * type IteratorResultValue = ITSTypeOfIterator<IteratorResult<number>>;
37
+ * // type IteratorResultValue = number
38
+ */
5
39
  export type ITSTypeOfIterator<T extends ITSIteratorLazy<any>> = T extends Iterator<infer U> ? U : T extends IteratorResult<infer U> ? U : any;
@@ -1,5 +1,11 @@
1
1
  "use strict";
2
2
  /**
3
+ * 類型推断工具
4
+ * Type Inference Utilities
5
+ *
6
+ * 提供迭代器和其他類型相關的工具類型
7
+ * Provides iterator and other type-related utility types
8
+ *
3
9
  * Created by user on 2019/6/11.
4
10
  */
5
11
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"typeof.js","sourceRoot":"","sources":["typeof.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * Created by user on 2019/6/11.\n */\n\n\nexport type ITSIteratorLazy<T extends Iterator<any> | IteratorResult<any>> =\n//\tT\n\tT extends IteratorResult<infer U> ? IteratorResult<U> :\n\t\tT extends Iterator<infer U> ? Iterator<U> :\n\t\t\tT\n\t;\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"]}
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.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { ITSArrayListMaybeReadonly } from './type/base';
2
2
  import { ITSAwaitedReturnType } from './helper/promise';
3
3
  /**
4
- * copy current function with Parameters and return to new value
4
+ * 複製當前函數的參數並返回新的值類型
5
+ * Copy current function with Parameters and return to new value
5
6
  *
6
- * not support overload
7
+ * 不支援函數重載
8
+ * Not support overload
7
9
  *
8
10
  * @example
9
11
  * declare function f(a: number): number
@@ -11,10 +13,25 @@ import { ITSAwaitedReturnType } from './helper/promise';
11
13
  * // c = (a: number) => string
12
14
  */
13
15
  export type ITSOverwriteReturnType<T extends (...args: any[]) => any, R extends unknown> = (...args: Parameters<T>) => R;
16
+ /**
17
+ * 將函數包裝為返回 PromiseLike 的版本
18
+ * Wrap function to return PromiseLike version
19
+ */
14
20
  export type ITSWrapFunctionPromiseLike<T extends (...args: any[]) => any> = (...args: Parameters<T>) => PromiseLike<ITSAwaitedReturnType<T>>;
21
+ /**
22
+ * 將函數包裝為返回 Promise 的版本
23
+ * Wrap function to return Promise version
24
+ */
15
25
  export type ITSWrapFunctionPromise<T extends (...args: any[]) => any> = (...args: Parameters<T>) => Promise<ITSAwaitedReturnType<T>>;
16
26
  /**
17
- * @deprecated
27
+ * 擴展類型檢查:從 T 中提取屬於 U 的部分
28
+ * Extend type check: extract parts of T that belong to U
29
+ *
30
+ * @deprecated 已棄用 / Deprecated
18
31
  */
19
32
  export type ITSExtendsOf<T, U> = Extract<T, U>;
33
+ /**
34
+ * 取得陣列類型的數字索引鍵
35
+ * Get numeric index keys of array type
36
+ */
20
37
  export type ITSKeyOfArray<T extends ITSArrayListMaybeReadonly<any>> = Exclude<keyof T, symbol | string>;
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\n\n/**\n * copy current function with Parameters and return to new value\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\nexport type ITSWrapFunctionPromiseLike<T extends (...args: any[]) => any> =\n\t(...args: Parameters<T>) => PromiseLike<ITSAwaitedReturnType<T>>;\nexport type ITSWrapFunctionPromise<T extends (...args: any[]) => any> =\n\t(...args: Parameters<T>) => Promise<ITSAwaitedReturnType<T>>;\n\n/**\n * @deprecated\n */\nexport type ITSExtendsOf<T, U> = Extract<T, U>;\n\nexport type ITSKeyOfArray<T extends ITSArrayListMaybeReadonly<any>> = Exclude<keyof T, symbol | string>;\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/**\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"]}
@@ -1 +1,8 @@
1
+ /**
2
+ * 內部過濾工具(內部使用)
3
+ * Internal Filter Utilities (Internal Use)
4
+ *
5
+ * 提供內部使用的過濾類型工具
6
+ * Provides internal filter type utilities
7
+ */
1
8
  export {};
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * 內部過濾工具(內部使用)
4
+ * Internal Filter Utilities (Internal Use)
5
+ *
6
+ * 提供內部使用的過濾類型工具
7
+ * Provides internal filter type utilities
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  //# sourceMappingURL=filter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.js","sourceRoot":"","sources":["filter.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSExtract2 } from '../helper/filter';\n\ntype I_RecordOfMatchKey<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: ITSExtract2<M[P], T, P>;\n};\n\ntype I_RecordOfMatchValue<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: ITSExtract2<M[P], T>;\n};\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,8 +1,41 @@
1
1
  /**
2
- * detect if T is a union
2
+ * 內部字串字面量邏輯工具(內部使用)
3
+ * Internal String Literal Logic Utilities (Internal Use)
4
+ *
5
+ * 提供內部使用的字串字面量邏輯判斷工具
6
+ * Provides internal string literal logic detection utilities
7
+ */
8
+ /**
9
+ * 檢測 T 是否為聯合類型(內部使用)
10
+ * Detect if T is a union type (internal use)
11
+ *
12
+ * @internal
13
+ *
14
+ * @example
15
+ * type Test1 = IsAUnion<'a' | 'b'>;
16
+ * // type Test1 = true
17
+ *
18
+ * @example
19
+ * type Test2 = IsAUnion<'a'>;
20
+ * // type Test2 = false
3
21
  */
4
22
  export type IsAUnion<T, Y = true, N = false, U = T> = U extends any ? ([T] extends [U] ? N : Y) : never;
5
23
  /**
6
- * detect if T is a single string literal
24
+ * 檢測 T 是否為單一字串字面量(內部使用)
25
+ * Detect if T is a single string literal (internal use)
26
+ *
27
+ * @internal
28
+ *
29
+ * @example
30
+ * type Test1 = IsASingleStringLiteral<'hello'>;
31
+ * // type Test1 = true
32
+ *
33
+ * @example
34
+ * type Test2 = IsASingleStringLiteral<'a' | 'b'>;
35
+ * // type Test2 = false
36
+ *
37
+ * @example
38
+ * type Test3 = IsASingleStringLiteral<string>;
39
+ * // type Test3 = false
7
40
  */
8
41
  export type IsASingleStringLiteral<T extends string, Y = true, N = false> = string extends T ? N : [T] extends [never] ? N : IsAUnion<T, N, Y>;
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * 內部字串字面量邏輯工具(內部使用)
4
+ * Internal String Literal Logic Utilities (Internal Use)
5
+ *
6
+ * 提供內部使用的字串字面量邏輯判斷工具
7
+ * Provides internal string literal logic detection utilities
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  //# sourceMappingURL=string-literal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string-literal.js","sourceRoot":"","sources":["string-literal.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * detect if T is a union\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 * detect if T is a single string literal\n */\nexport type IsASingleStringLiteral<\n\tT extends string,\n\tY = true,\n\tN = false\n\t> = string extends T ? N : [T] extends [never] ? N : IsAUnion<T, N, Y>;\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\t> = string extends T ? N : [T] extends [never] ? N : IsAUnion<T, N, Y>;\n"]}
@@ -1,5 +1,38 @@
1
1
  /**
2
+ * Any 類型判斷工具
3
+ * Any Type Detection Utilities
4
+ *
5
+ * 提供檢測類型是否為 any 的工具
6
+ * Provides utilities for detecting if a type is any
7
+ *
2
8
  * @see https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
3
9
  */
10
+ /**
11
+ * 檢測類型是否為 any
12
+ * Detect if a type is any
13
+ *
14
+ * 利用 any 與任何類型交叉都會得到 any 的特性來檢測
15
+ * Uses the fact that any intersected with any type still results in any
16
+ *
17
+ * @example
18
+ * type Test1 = ITSLogicIsAny<any>;
19
+ * // type Test1 = true
20
+ *
21
+ * @example
22
+ * type Test2 = ITSLogicIsAny<string>;
23
+ * // type Test2 = false
24
+ */
4
25
  export type ITSLogicIsAny<T, Y = true, N = false> = 0 extends (1 & T) ? Y : N;
26
+ /**
27
+ * 檢測類型是否不為 any
28
+ * Detect if a type is not any
29
+ *
30
+ * @example
31
+ * type Test1 = ITSLogicNotAny<any>;
32
+ * // type Test1 = false
33
+ *
34
+ * @example
35
+ * type Test2 = ITSLogicNotAny<string>;
36
+ * // type Test2 = true
37
+ */
5
38
  export type ITSLogicNotAny<T, Y = true, N = false> = ITSLogicIsAny<T, N, Y>;
package/lib/logic/any.js CHANGED
@@ -1,3 +1,12 @@
1
1
  "use strict";
2
+ /**
3
+ * Any 類型判斷工具
4
+ * Any Type Detection Utilities
5
+ *
6
+ * 提供檢測類型是否為 any 的工具
7
+ * Provides utilities for detecting if a type is any
8
+ *
9
+ * @see https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
10
+ */
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  //# sourceMappingURL=any.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"any.js","sourceRoot":"","sources":["any.ts"],"names":[],"mappings":"","sourcesContent":["\n/**\n * @see https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360\n */\nexport type ITSLogicIsAny<T, Y = true, N = false> = 0 extends (1 & T) ? Y : N\n\nexport type ITSLogicNotAny<T, Y = true, N = false> = ITSLogicIsAny<T, N, Y>\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"]}
@@ -1 +1,23 @@
1
+ /**
2
+ * Never 類型判斷工具
3
+ * Never Type Detection Utilities
4
+ *
5
+ * 提供檢測類型是否為 never 的工具
6
+ * Provides utilities for detecting if a type is never
7
+ */
8
+ /**
9
+ * 檢測類型是否為 never
10
+ * Detect if a type is never
11
+ *
12
+ * 利用 never 是所有類型的子類型特性來檢測
13
+ * Uses the fact that never is a subtype of all types
14
+ *
15
+ * @example
16
+ * type Test1 = ITSLogicIsNever<never>;
17
+ * // type Test1 = true
18
+ *
19
+ * @example
20
+ * type Test2 = ITSLogicIsNever<string>;
21
+ * // type Test2 = false
22
+ */
1
23
  export type ITSLogicIsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Never 類型判斷工具
4
+ * Never Type Detection Utilities
5
+ *
6
+ * 提供檢測類型是否為 never 的工具
7
+ * Provides utilities for detecting if a type is never
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  //# sourceMappingURL=never.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"never.js","sourceRoot":"","sources":["never.ts"],"names":[],"mappings":"","sourcesContent":["\nexport type ITSLogicIsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N\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,15 +1,41 @@
1
+ /**
2
+ * 聯合類型邏輯工具
3
+ * Union Type Logic Utilities
4
+ *
5
+ * 提供聯合類型相關的邏輯判斷工具
6
+ * Provides union type-related logic detection utilities
7
+ */
1
8
  import { ITSUnionToIntersection } from '../../helper/intersection';
2
9
  import { ITSLogicIsNever } from '../never';
10
+ /**
11
+ * 檢測類型是否為聯合類型
12
+ * Detect if a type is a union type
13
+ *
14
+ * @example
15
+ * type Test1 = ITSLogicIsUnion<string | number>;
16
+ * // type Test1 = true
17
+ *
18
+ * @example
19
+ * type Test2 = ITSLogicIsUnion<string>;
20
+ * // type Test2 = false
21
+ */
3
22
  export type ITSLogicIsUnion<T, Y = true, N = false> = [T] extends [ITSUnionToIntersection<T>] ? N : Y;
4
23
  /**
24
+ * 檢測類型是否為單一非聯合類型
25
+ * Detect if a type is a single non-union type
26
+ *
5
27
  * @see https://stackoverflow.com/a/49982981/4563339
28
+ *
6
29
  * @example
7
- * let a: ITSLogicIsSingleNonUnion01<'' | '4' | any, string>
8
- * let b: ITSLogicIsSingleNonUnion01<'' & '4' & any, string>
9
- * let c: ITSLogicIsSingleNonUnion01<'', string>
30
+ * type Test1 = ITSLogicIsSingleNonUnion01<'' | '4' | any, string>;
31
+ * // type Test1 = false (因為是聯合類型)
10
32
  *
11
- * expectType<false>(a);
12
- * expectType<false>(b);
13
- * expectType<true>(c);
33
+ * @example
34
+ * type Test2 = ITSLogicIsSingleNonUnion01<'' & '4' & any, string>;
35
+ * // type Test2 = false (因為是交集類型)
36
+ *
37
+ * @example
38
+ * type Test3 = ITSLogicIsSingleNonUnion01<'', string>;
39
+ * // type Test3 = true (因為是單一類型)
14
40
  */
15
41
  export type ITSLogicIsSingleNonUnion01<T, U extends any, Y = true, N = false> = U extends T ? N : ITSLogicIsNever<T, N, ITSLogicIsUnion<T, N, Y>>;
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * 聯合類型邏輯工具
4
+ * Union Type Logic Utilities
5
+ *
6
+ * 提供聯合類型相關的邏輯判斷工具
7
+ * Provides union type-related logic detection utilities
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSUnionToIntersection } from '../../helper/intersection';\nimport { ITSLogicIsNever } from '../never';\n\nexport type ITSLogicIsUnion<T, Y = true, N = false> = [T] extends [ITSUnionToIntersection<T>] ? N : Y\n\n/**\n * @see https://stackoverflow.com/a/49982981/4563339\n * @example\n * let a: ITSLogicIsSingleNonUnion01<'' | '4' | any, string>\n * let b: ITSLogicIsSingleNonUnion01<'' & '4' & any, string>\n * let c: ITSLogicIsSingleNonUnion01<'', string>\n *\n * expectType<false>(a);\n * expectType<false>(b);\n * expectType<true>(c);\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\n\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"]}
@@ -1,13 +1,89 @@
1
1
  /**
2
- * Created by user on 2019/5/17.
2
+ * 基礎類型定義
3
+ * Base Type Definitions
4
+ *
5
+ * 提供常用的基礎類型別名和工具類型
6
+ * Provides commonly used base type aliases and utility types
3
7
  */
4
8
  import { ITSTypeFunction } from '../generic';
9
+ /**
10
+ * 陣列類型:可讀寫陣列或唯讀陣列
11
+ * Array type: writable array or readonly array
12
+ *
13
+ * @example
14
+ * type StringList = ITSArrayListMaybeReadonly<string>;
15
+ * // type StringList = string[] | readonly string[]
16
+ */
5
17
  export type ITSArrayListMaybeReadonly<T> = T[] | readonly T[];
18
+ /**
19
+ * 鍵的類型:符號、字串或數字
20
+ * Key types: symbol, string, or number
21
+ *
22
+ * @example
23
+ * type Keys = ITSKeys;
24
+ * // type Keys = symbol | string | number
25
+ */
6
26
  export type ITSKeys = symbol | string | number;
27
+ /**
28
+ * 建構函數類型
29
+ * Constructor type
30
+ *
31
+ * @example
32
+ * type MyConstructor = ITSConstructorLike<MyClass>;
33
+ * // type MyConstructor = new (...args: any) => MyClass
34
+ */
7
35
  export type ITSConstructorLike<T extends any = any> = new (...args: any) => T;
36
+ /**
37
+ * 值或陣列:單一值或其陣列
38
+ * Value or array: single value or array of that value
39
+ *
40
+ * @example
41
+ * type StringOrArray = ITSValueOrArray<string>;
42
+ * // type StringOrArray = string | string[]
43
+ */
8
44
  export type ITSValueOrArray<T> = T | T[];
45
+ /**
46
+ * 值或可能唯讀的陣列:單一值、可讀寫陣列或唯讀陣列
47
+ * Value or possibly readonly array: single value, writable array, or readonly array
48
+ *
49
+ * @example
50
+ * type StringOrList = ITSValueOrArrayMaybeReadonly<string>;
51
+ * // type StringOrList = string | string[] | readonly string[]
52
+ */
9
53
  export type ITSValueOrArrayMaybeReadonly<T> = T | ITSArrayListMaybeReadonly<T>;
54
+ /**
55
+ * 屬性鍵類型:字串或符號
56
+ * Property key type: string or symbol
57
+ *
58
+ * @example
59
+ * type PropKey = ITSPropertyKey;
60
+ * // type PropKey = string | symbol
61
+ */
10
62
  export type ITSPropertyKey = string | symbol;
63
+ /**
64
+ * 任意函數類型
65
+ * Any function type
66
+ *
67
+ * @example
68
+ * type AnyFunc = ITSAnyFunction;
69
+ * // type AnyFunc = (...args: any[]) => any
70
+ */
11
71
  export type ITSAnyFunction = ITSTypeFunction<any>;
72
+ /**
73
+ * 基本原始類型:數字、字串或布林值
74
+ * Basic primitive types: number, string, or boolean
75
+ *
76
+ * @example
77
+ * type Primitive = ITSBasicPrimitive;
78
+ * // type Primitive = number | string | boolean
79
+ */
12
80
  export type ITSBasicPrimitive = number | string | boolean;
81
+ /**
82
+ * 可為空的原始類型:null 或 undefined
83
+ * Nullable primitive types: null or undefined
84
+ *
85
+ * @example
86
+ * type Nullish = ITSNullPrimitive;
87
+ * // type Nullish = null | undefined
88
+ */
13
89
  export type ITSNullPrimitive = null | undefined;
package/lib/type/base.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  /**
3
- * Created by user on 2019/5/17.
3
+ * 基礎類型定義
4
+ * Base Type Definitions
5
+ *
6
+ * 提供常用的基礎類型別名和工具類型
7
+ * Provides commonly used base type aliases and utility types
4
8
  */
5
9
  Object.defineProperty(exports, "__esModule", { value: true });
6
10
  //# sourceMappingURL=base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["base.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * Created by user on 2019/5/17.\n */\n\nimport { ITSTypeFunction } from '../generic';\n\nexport type ITSArrayListMaybeReadonly<T> = T[] | readonly T[];\n\nexport type ITSKeys = symbol | string | number;\n\nexport type ITSConstructorLike<T extends any = any> = new(...args: any) => T;\n\nexport type ITSValueOrArray<T> = T | T[];\n\nexport type ITSValueOrArrayMaybeReadonly<T> = T | ITSArrayListMaybeReadonly<T>;\n\nexport type ITSPropertyKey = string | symbol;\n\nexport type ITSAnyFunction = ITSTypeFunction<any>;\n\nexport type ITSBasicPrimitive = number | string | boolean;\n\nexport type ITSNullPrimitive = null | undefined;\n\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 * 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,2 +1,25 @@
1
+ /**
2
+ * 迭代器類型定義
3
+ * Iterator Type Definitions
4
+ *
5
+ * 提供 Iterator 和 IteratorResult 的類型定義
6
+ * Provides Iterator and IteratorResult type definitions
7
+ */
8
+ /**
9
+ * Iterator 類型
10
+ * Iterator type
11
+ *
12
+ * @example
13
+ * const iterator: ITSIterator<string> = {
14
+ * next() { return { done: false, value: 'test' }; }
15
+ * };
16
+ */
1
17
  export type ITSIterator<T, TReturn = void, TNext = undefined> = Iterator<T, TReturn, TNext>;
18
+ /**
19
+ * IteratorResult 類型
20
+ * IteratorResult type
21
+ *
22
+ * @example
23
+ * const result: ITSIteratorResult<string> = { done: false, value: 'test' };
24
+ */
2
25
  export type ITSIteratorResult<T, TReturn = void> = IteratorResult<T, TReturn>;
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * 迭代器類型定義
4
+ * Iterator Type Definitions
5
+ *
6
+ * 提供 Iterator 和 IteratorResult 的類型定義
7
+ * Provides Iterator and IteratorResult type definitions
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  //# sourceMappingURL=iterator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iterator.js","sourceRoot":"","sources":["iterator.ts"],"names":[],"mappings":"","sourcesContent":["\nexport type ITSIterator<T, TReturn = void, TNext = undefined> = Iterator<T, TReturn, TNext>;\n\nexport type ITSIteratorResult<T, TReturn = void> = IteratorResult<T, TReturn>;\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"]}
@@ -1,21 +1,81 @@
1
1
  /**
2
+ * Promise 類型工具
3
+ * Promise Type Utilities
4
+ *
5
+ * 提供 Promise 相關的類型操作工具
6
+ * Provides Promise-related type manipulation utilities
7
+ *
2
8
  * Created by user on 2019/6/11.
3
9
  */
4
10
  /**
5
- * Same property names, but make the value a promise instead of a concrete one
11
+ * 延遲物件類型:將物件的所有屬性包裝為 Promise
12
+ * Deferred object type: wraps all properties of an object in Promise
13
+ *
14
+ * 保持相同的屬性名稱,但將值類型包裝為 Promise
15
+ * Keeps the same property names, but wraps value types in Promise
16
+ *
6
17
  * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html
18
+ *
19
+ * @example
20
+ * interface User {
21
+ * id: number;
22
+ * name: string;
23
+ * }
24
+ * type DeferredUser = ITSDeferred<User>;
25
+ * // type DeferredUser = { id: Promise<number>; name: Promise<string>; }
7
26
  */
8
27
  export type ITSDeferred<T> = {
9
28
  [P in keyof T]: Promise<T[P]>;
10
29
  };
30
+ /**
31
+ * Promise 解決結果介面
32
+ * Promise fulfilled result interface
33
+ *
34
+ * 表示 Promise 已成功解決
35
+ * Represents a promise that has been successfully resolved
36
+ *
37
+ * @example
38
+ * const fulfilled: ITSPromiseFulfilledResult<string> = {
39
+ * status: "fulfilled",
40
+ * value: "success"
41
+ * };
42
+ */
11
43
  export interface ITSPromiseFulfilledResult<T> {
44
+ /** 解決狀態 / Fulfilled status */
12
45
  status: "fulfilled";
46
+ /** 解決值 / Resolved value */
13
47
  value: T;
48
+ /** 永不存在的拒絕原因 / Reason that never exists */
14
49
  reason?: never;
15
50
  }
51
+ /**
52
+ * Promise 拒絕結果介面
53
+ * Promise rejected result interface
54
+ *
55
+ * 表示 Promise 被拒絕
56
+ * Represents a promise that has been rejected
57
+ *
58
+ * @example
59
+ * const rejected: ITSPromiseRejectedResult<Error> = {
60
+ * status: "rejected",
61
+ * reason: new Error("failed")
62
+ * };
63
+ */
16
64
  export interface ITSPromiseRejectedResult<E = any> {
65
+ /** 拒絕狀態 / Rejected status */
17
66
  status: "rejected";
67
+ /** 拒絕原因 / Rejection reason */
18
68
  reason: E;
69
+ /** 永不存在的解決值 / Value that never exists */
19
70
  value?: never;
20
71
  }
72
+ /**
73
+ * Promise settled 結果類型:解決或拒絕結果的聯合類型
74
+ * Promise settled result type: union of fulfilled or rejected result
75
+ *
76
+ * @example
77
+ * const result: ITSPromiseSettledResult<string> = Math.random() > 0.5
78
+ * ? { status: "fulfilled", value: "success" }
79
+ * : { status: "rejected", reason: new Error("failed") };
80
+ */
21
81
  export type ITSPromiseSettledResult<T, E = any> = ITSPromiseFulfilledResult<T> | ITSPromiseRejectedResult<E>;