ts-type 2.1.10 → 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 (131) hide show
  1. package/CHANGELOG.md +72 -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/index.js +0 -2
  13. package/lib/_build-in.d.ts +68 -13
  14. package/lib/_build-in.js +7 -2
  15. package/lib/_build-in.js.map +1 -1
  16. package/lib/generic.d.ts +35 -2
  17. package/lib/generic.js.map +1 -1
  18. package/lib/helper/array/readonly.d.ts +18 -2
  19. package/lib/helper/array/readonly.js.map +1 -1
  20. package/lib/helper/filter.d.ts +72 -14
  21. package/lib/helper/filter.js.map +1 -1
  22. package/lib/helper/infer.d.ts +21 -2
  23. package/lib/helper/infer.js.map +1 -1
  24. package/lib/helper/intersection.d.ts +4 -1
  25. package/lib/helper/intersection.js.map +1 -1
  26. package/lib/helper/key-value.d.ts +99 -9
  27. package/lib/helper/key-value.js +5 -1
  28. package/lib/helper/key-value.js.map +1 -1
  29. package/lib/helper/number.d.ts +27 -4
  30. package/lib/helper/number.js.map +1 -1
  31. package/lib/helper/overwrite.d.ts +5 -1
  32. package/lib/helper/overwrite.js.map +1 -1
  33. package/lib/helper/promise.d.ts +11 -0
  34. package/lib/helper/{unpacked.js → promise.js} +1 -1
  35. package/lib/helper/promise.js.map +1 -0
  36. package/lib/helper/readonly.d.ts +124 -12
  37. package/lib/helper/readonly.js.map +1 -1
  38. package/lib/helper/record/enum.d.ts +50 -3
  39. package/lib/helper/record/enum.js +7 -0
  40. package/lib/helper/record/enum.js.map +1 -1
  41. package/lib/helper/record/member.d.ts +33 -3
  42. package/lib/helper/record/member.js +7 -0
  43. package/lib/helper/record/member.js.map +1 -1
  44. package/lib/helper/record/omit-index.d.ts +52 -3
  45. package/lib/helper/record/omit-index.js +7 -1
  46. package/lib/helper/record/omit-index.js.map +1 -1
  47. package/lib/helper/record/partial.d.ts +29 -2
  48. package/lib/helper/record/partial.js +7 -0
  49. package/lib/helper/record/partial.js.map +1 -1
  50. package/lib/helper/record/pick-one.d.ts +9 -0
  51. package/lib/{type/bluebird.js → helper/record/pick-one.js} +1 -4
  52. package/lib/helper/record/pick-one.js.map +1 -0
  53. package/lib/helper/record/pick-type.d.ts +16 -16
  54. package/lib/helper/record.d.ts +61 -10
  55. package/lib/helper/record.js +7 -1
  56. package/lib/helper/record.js.map +1 -1
  57. package/lib/helper/string/infer.d.ts +60 -0
  58. package/lib/helper/string/infer.js +10 -0
  59. package/lib/helper/string/infer.js.map +1 -0
  60. package/lib/helper/string/literal-string.d.ts +31 -4
  61. package/lib/helper/string/literal-string.js +7 -0
  62. package/lib/helper/string/literal-string.js.map +1 -1
  63. package/lib/helper/string.d.ts +64 -6
  64. package/lib/helper/string.js +7 -0
  65. package/lib/helper/string.js.map +1 -1
  66. package/lib/helper/tuple.d.ts +16 -3
  67. package/lib/helper/tuple.js +7 -0
  68. package/lib/helper/tuple.js.map +1 -1
  69. package/lib/helper/typeof.d.ts +36 -3
  70. package/lib/helper/typeof.js +6 -0
  71. package/lib/helper/typeof.js.map +1 -1
  72. package/lib/helper.d.ts +26 -11
  73. package/lib/helper.js.map +1 -1
  74. package/lib/index.d.ts +5 -2
  75. package/lib/index.js +0 -2
  76. package/lib/internal/filter.d.ts +7 -0
  77. package/lib/internal/filter.js +7 -0
  78. package/lib/internal/filter.js.map +1 -1
  79. package/lib/internal/logic/string-literal.d.ts +37 -4
  80. package/lib/internal/logic/string-literal.js +7 -0
  81. package/lib/internal/logic/string-literal.js.map +1 -1
  82. package/lib/logic/any.d.ts +35 -2
  83. package/lib/logic/any.js +9 -0
  84. package/lib/logic/any.js.map +1 -1
  85. package/lib/logic/never.d.ts +23 -1
  86. package/lib/logic/never.js +7 -0
  87. package/lib/logic/never.js.map +1 -1
  88. package/lib/logic/record/empty.d.ts +1 -1
  89. package/lib/logic/union/index.d.ts +41 -0
  90. package/lib/logic/union/index.js +10 -0
  91. package/lib/logic/union/index.js.map +1 -0
  92. package/lib/type/base.d.ts +86 -10
  93. package/lib/type/base.js +5 -1
  94. package/lib/type/base.js.map +1 -1
  95. package/lib/type/iterator.d.ts +25 -0
  96. package/lib/type/iterator.js +10 -0
  97. package/lib/type/iterator.js.map +1 -0
  98. package/lib/type/promise.d.ts +63 -3
  99. package/lib/type/promise.js +6 -0
  100. package/lib/type/promise.js.map +1 -1
  101. package/lib/type/proxy.d.ts +20 -3
  102. package/lib/type/proxy.js +5 -1
  103. package/lib/type/proxy.js.map +1 -1
  104. package/lib/type/record/empty.d.ts +26 -2
  105. package/lib/type/record/empty.js +9 -0
  106. package/lib/type/record/empty.js.map +1 -1
  107. package/lib/type/record/enum.d.ts +65 -1
  108. package/lib/type/record/enum.js +7 -0
  109. package/lib/type/record/enum.js.map +1 -1
  110. package/lib/type/record/partial.d.ts +31 -2
  111. package/lib/type/record/partial.js +7 -0
  112. package/lib/type/record/partial.js.map +1 -1
  113. package/lib/type/record/readonly.d.ts +33 -1
  114. package/lib/type/record/readonly.js +7 -0
  115. package/lib/type/record/readonly.js.map +1 -1
  116. package/lib/type/record.d.ts +157 -35
  117. package/lib/type/record.js +6 -0
  118. package/lib/type/record.js.map +1 -1
  119. package/lib/type/tuple/empty.d.ts +16 -1
  120. package/lib/type/tuple/empty.js +7 -0
  121. package/lib/type/tuple/empty.js.map +1 -1
  122. package/package.json +48 -15
  123. package/ts-toolbelt.js +0 -2
  124. package/lib/helper/unpacked.d.ts +0 -13
  125. package/lib/helper/unpacked.js.map +0 -1
  126. package/lib/type/bluebird.d.ts +0 -19
  127. package/lib/type/bluebird.js.map +0 -1
  128. package/tsconfig.check.json +0 -17
  129. package/tsconfig.check.tsbuildinfo +0 -1
  130. package/tsconfig.json.tpl +0 -3
  131. package/tsconfig.tsbuildinfo +0 -3148
package/CHANGELOG.md CHANGED
@@ -3,6 +3,78 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.2](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.1...ts-type@3.0.2) (2026-03-07)
7
+
8
+
9
+
10
+ ### 📦 Code Refactoring
11
+
12
+ * **ts-type:** 移除不必要的建置工具配置與未使用的引入 ([dc65314](https://github.com/bluelovers/ws-ts-type/commit/dc65314333a9a04dfb3dd857d1617ab253dfeadc))
13
+
14
+
15
+ ### 📚 Documentation
16
+
17
+ * **ts-type:** 為類型定義檔案新增雙語 JSDoc 註解 ([6969bbc](https://github.com/bluelovers/ws-ts-type/commit/6969bbcaf991b973d7e4687bfac2d8ae9ecc09ab))
18
+ * **ts-type:** add iterator and proxy type documentation ([6d93ce4](https://github.com/bluelovers/ws-ts-type/commit/6d93ce49526c0081108a639c88c7e2c119fe10f4))
19
+ * **ts-type:** add category guide to README ([26f5860](https://github.com/bluelovers/ws-ts-type/commit/26f586006064c55ef9f1fcf543e7f4c4208b39f8))
20
+ * **ts-type:** 為類型定義檔案新增雙語 JSDoc 註解 ([93836f5](https://github.com/bluelovers/ws-ts-type/commit/93836f5e3b7e3efa949a91a52702d454a62b60ab))
21
+ * **ts-type:** 更新 README 与 package.json 文档,增加双语说明 ([81d926d](https://github.com/bluelovers/ws-ts-type/commit/81d926da85ca492b6810fa20a0b574db75f4ece9))
22
+ * **ts-type:** 新增 ts-type 類型工具庫的完整文檔 ([cba3d50](https://github.com/bluelovers/ws-ts-type/commit/cba3d50752dabbb106444bf060f7d00c176014cf))
23
+ * **ts-type:** add bilingual JSDoc comments to helper and type definition files ([e96a0fd](https://github.com/bluelovers/ws-ts-type/commit/e96a0fd66457639e13d61d9a8926a64ca13b7548))
24
+ * **ts-type:** add bilingual JSDoc comments to helper types and test files ([5893036](https://github.com/bluelovers/ws-ts-type/commit/58930369f50f454595241e5573bdcc03dea4654b))
25
+ * **ts-type:** add bilingual JSDoc comments to type definitions ([8b34984](https://github.com/bluelovers/ws-ts-type/commit/8b349843c65ebf4bd3bb428119243129a07a07c8))
26
+
27
+
28
+ ### 🛠 Build System
29
+
30
+ * 更新多個套件的 test 指令為 jest ([61ea53b](https://github.com/bluelovers/ws-ts-type/commit/61ea53bf15fc3ed0e216793200604ae5a52079c9))
31
+
32
+
33
+ ### ♻️ Chores
34
+
35
+ * migrate from yarn to pnpm and enhance test infrastructure ([8a5daa2](https://github.com/bluelovers/ws-ts-type/commit/8a5daa2f2022eaf025c3349d4fe5dc8971f8c077))
36
+
37
+
38
+
39
+ ## [3.0.1](https://github.com/bluelovers/ws-ts-type/compare/ts-type@2.1.10...ts-type@3.0.1) (2022-10-10)
40
+
41
+
42
+ ### BREAKING CHANGES
43
+
44
+ * remove `unpacked` , `bluebird`
45
+ * .
46
+
47
+
48
+
49
+ ### ✨ Features
50
+
51
+ * `ITSStringInferToType` ([cbc1788](https://github.com/bluelovers/ws-ts-type/commit/cbc1788d087a320d2dd837c42cd353d3a43a34f3))
52
+ * ITSPickOne ([4f056cd](https://github.com/bluelovers/ws-ts-type/commit/4f056cdf4078ac06adea3c82bd000229714039d2))
53
+ * remove `unpacked` , `bluebird` ([52247d9](https://github.com/bluelovers/ws-ts-type/commit/52247d98ca482f5d0dfe879d3c6d69936dcfa195))
54
+
55
+
56
+ ### 📦 Code Refactoring
57
+
58
+ * . ([b656466](https://github.com/bluelovers/ws-ts-type/commit/b656466b216e331293acb9c77b36054cb0bd0c2b))
59
+
60
+
61
+ ### 🛠 Build System
62
+
63
+ * update typescript ([eb59d89](https://github.com/bluelovers/ws-ts-type/commit/eb59d897c2888c7a45406ffcad4b9033608b0b66))
64
+
65
+
66
+ ### 📌 Dependencies
67
+
68
+ * update deps ([ab5f3e4](https://github.com/bluelovers/ws-ts-type/commit/ab5f3e48da1f10ddd4445ba6dda9a0a68c5f656f))
69
+
70
+
71
+ ### 🔖 Miscellaneous
72
+
73
+ * . ([6588a93](https://github.com/bluelovers/ws-ts-type/commit/6588a932156f6e44e746b3ae2452336a04833153))
74
+ * . ([4eddd02](https://github.com/bluelovers/ws-ts-type/commit/4eddd023316693edd41fda4e2c6338bc507775a6))
75
+
76
+
77
+
6
78
  ## [2.1.10](https://github.com/bluelovers/ws-ts-type/compare/ts-type@2.1.9...ts-type@2.1.10) (2022-08-10)
7
79
 
8
80
 
package/README.md CHANGED
@@ -1,16 +1,27 @@
1
- # README
1
+ # ts-type
2
2
 
3
- add some typescript type and re-export some build-in typescript type
3
+ **TypeScript 類型工具庫** / **TypeScript Type Utility Library**
4
+
5
+ 提供豐富的 TypeScript 類型操作工具和重新導出的內建類型,支援雙語註解(繁體中文 + 英文)。
6
+
7
+ Provides rich TypeScript type manipulation utilities and re-exported built-in types with bilingual comments (Traditional Chinese + English).
4
8
 
5
9
  see [index.d.ts](https://github.com/bluelovers/ws-ts-type/tree/master/packages/ts-type/index.d.ts)
6
10
 
7
- ## install
11
+ ## 安裝 / Installation
8
12
 
9
- ```nodemon
13
+ ```bash
14
+ # npm
10
15
  npm install ts-type
16
+
17
+ # yarn
18
+ yarn add ts-type
19
+
20
+ # pnpm
21
+ pnpm add ts-type
11
22
  ```
12
23
 
13
- ## demo
24
+ ## 範例 / Examples
14
25
 
15
26
  - [demo](https://github.com/bluelovers/ws-ts-type/tree/master/packages/ts-type/test/demo)
16
27
  -
@@ -32,6 +43,8 @@ export declare let a2: A2;
32
43
 
33
44
  ### ITSOverwriteReturnType
34
45
 
46
+ 覆寫函數返回值類型 / Overwrite function return type
47
+
35
48
  ```ts
36
49
  import { ITSOverwriteReturnType } from '..';
37
50
 
@@ -44,6 +57,8 @@ declare let c: ITSOverwriteReturnType<typeof f, string>;
44
57
 
45
58
  ### Promise / Bluebird / PromiseLike
46
59
 
60
+ Promise 相關類型操作 / Promise related type operations
61
+
47
62
  ```nodemon
48
63
  npm install @types/bluebird ts-type
49
64
  ```
@@ -64,7 +79,9 @@ p3(1).then(v => v.toFixed())
64
79
  p4(1).then(v => v.toFixed())
65
80
  ```
66
81
 
67
- ### this
82
+ ### this 類型操作 / this Type Operations
83
+
84
+ 操作函數的 this 類型 / Manipulate function's this type
68
85
 
69
86
  ```ts
70
87
  export declare function t1(this: string, a: number): Promise<number>
@@ -110,19 +127,36 @@ t6 = function ()
110
127
  }
111
128
  ```
112
129
 
113
- ## other
130
+ ## 文檔 / Documentation
131
+
132
+ 詳細的類型工具說明文件請參閱 [docs/](docs/) 目錄。
133
+
134
+ For detailed type utility documentation, see the [docs/](docs/) directory.
135
+
136
+ ### 分類指南 / Category Guide
137
+
138
+ - [基礎類型](docs/01-base-types.md) - 基礎類型別名與工具 / Base type aliases and utilities
139
+ - [內建類型](docs/02-built-in-types.md) - 重新導出的內建類型 / Re-exported built-in types
140
+ - [函數類型工具](docs/03-function-types.md) - 函數類型操作 / Function type operations
141
+ - [Promise 類型工具](docs/04-promise-types.md) - Promise 相關類型 / Promise related types
142
+ - [陣列與元組類型](docs/05-array-tuple-types.md) - 陣列與元組操作 / Array and tuple operations
143
+ - [物件與記錄類型](docs/06-object-record-types.md) - 物件類型操作 / Object type operations
144
+ - [字串與數字類型](docs/07-string-number-types.md) - 字串與數字類型操作 / String and number operations
145
+ - [邏輯類型工具](docs/08-logic-types.md) - 類型層級邏輯判斷 / Type-level logic
146
+
147
+ ## 其他相關專案 / Related Projects
114
148
 
115
149
  - [callable-instance2](https://www.npmjs.com/package/callable-instance2) - create an ES6 class that is callable as a function
116
150
  - https://github.com/piotrwitek/utility-types
117
151
  -
118
152
 
119
- ## docs
153
+ ## 文件與教學 / Documentation & Tutorials
120
154
 
121
155
  - http://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html
122
156
  - https://www.tslang.cn/docs/release-notes/typescript-3.1.html#toc-whats-new
123
157
  - https://www.logicbig.com/tutorials/misc/typescript.html
124
158
 
125
- ## links
159
+ ## 相關連結 / Related Links
126
160
 
127
161
  - https://github.com/krzkaczor/ts-essentials
128
162
  - https://github.com/millsp/ts-toolbelt
@@ -0,0 +1,218 @@
1
+ # 基礎類型 / Base Types
2
+
3
+ ## 概述 / Overview
4
+
5
+ 提供常用的基礎類型別名和工具類型,這些類型是整個庫的建構基礎。
6
+
7
+ Provides commonly used base type aliases and utility types that form the building blocks of the entire library.
8
+
9
+ ## 來源 / Source
10
+
11
+ - [`lib/type/base.ts`](../lib/type/base.ts)
12
+ - [`lib/generic.ts`](../lib/generic.ts)
13
+
14
+ ---
15
+
16
+ ## 類型列表 / Type List
17
+
18
+ ### ITSArrayListMaybeReadonly
19
+
20
+ **陣列類型:可讀寫陣列或唯讀陣列**
21
+
22
+ ```typescript
23
+ type StringList = ITSArrayListMaybeReadonly<string>;
24
+ // type StringList = string[] | readonly string[]
25
+ ```
26
+
27
+ ---
28
+
29
+ ### ITSKeys
30
+
31
+ **鍵的類型:符號、字串或數字**
32
+
33
+ ```typescript
34
+ type Keys = ITSKeys;
35
+ // type Keys = symbol | string | number
36
+ ```
37
+
38
+ ---
39
+
40
+ ### ITSConstructorLike
41
+
42
+ **建構函數類型**
43
+
44
+ ```typescript
45
+ type MyConstructor = ITSConstructorLike<MyClass>;
46
+ // type MyConstructor = new (...args: any) => MyClass
47
+ ```
48
+
49
+ ---
50
+
51
+ ### ITSValueOrArray
52
+
53
+ **值或陣列:單一值或其陣列**
54
+
55
+ ```typescript
56
+ type StringOrArray = ITSValueOrArray<string>;
57
+ // type StringOrArray = string | string[]
58
+ ```
59
+
60
+ ---
61
+
62
+ ### ITSValueOrArrayMaybeReadonly
63
+
64
+ **值或可能唯讀的陣列**
65
+
66
+ ```typescript
67
+ type StringOrList = ITSValueOrArrayMaybeReadonly<string>;
68
+ // type StringOrList = string | string[] | readonly string[]
69
+ ```
70
+
71
+ ---
72
+
73
+ ### ITSPropertyKey
74
+
75
+ **屬性鍵類型:字串或符號**
76
+
77
+ ```typescript
78
+ type PropKey = ITSPropertyKey;
79
+ // type PropKey = string | symbol
80
+ ```
81
+
82
+ ---
83
+
84
+ ### ITSAnyFunction
85
+
86
+ **任意函數類型**
87
+
88
+ ```typescript
89
+ type AnyFunc = ITSAnyFunction;
90
+ // type AnyFunc = (...args: any[]) => any
91
+ ```
92
+
93
+ ---
94
+
95
+ ### ITSBasicPrimitive
96
+
97
+ **基本原始類型:數字、字串或布林值**
98
+
99
+ ```typescript
100
+ type Primitive = ITSBasicPrimitive;
101
+ // type Primitive = number | string | boolean
102
+ ```
103
+
104
+ ---
105
+
106
+ ### ITSNullPrimitive
107
+
108
+ **可為空的原始類型:null 或 undefined**
109
+
110
+ ```typescript
111
+ type Nullish = ITSNullPrimitive;
112
+ // type Nullish = null | undefined
113
+ ```
114
+
115
+ ---
116
+
117
+ ## 泛型工具 / Generic Utilities
118
+
119
+ ### ITSTypeFunction
120
+
121
+ **類型函數:返回指定類型的函數**
122
+
123
+ ```typescript
124
+ type MyTypeFunc = ITSTypeFunction<string>;
125
+ // type MyTypeFunc = (...args: any[]) => string
126
+ ```
127
+
128
+ ---
129
+
130
+ ### ITSMapLike
131
+
132
+ **類似 Map 的介面定義**
133
+
134
+ ```typescript
135
+ interface MyMap extends ITSMapLike<string, number> {
136
+ get(key: string): number | undefined;
137
+ has(key: string): boolean;
138
+ }
139
+ ```
140
+
141
+ ---
142
+
143
+ ### ITSSetLike
144
+
145
+ **類似 Set 的介面定義**
146
+
147
+ ```typescript
148
+ interface MySet extends ITSSetLike<string> {
149
+ has(value: string): boolean;
150
+ }
151
+ ```
152
+
153
+ ---
154
+
155
+ ### ITSResolvable
156
+
157
+ **可解析的類型:支援直接值或 PromiseLike**
158
+
159
+ ```typescript
160
+ type AsyncValue = ITSResolvable<string>;
161
+ // type AsyncValue = string | PromiseLike<string>
162
+ ```
163
+
164
+ ---
165
+
166
+ ### ITSArrayLikeWriteable
167
+
168
+ **可寫入的類陣列介面**
169
+
170
+ ```typescript
171
+ interface MyArrayLike extends ITSArrayLikeWriteable<string> {
172
+ readonly length: number;
173
+ [n: number]: string;
174
+ }
175
+ ```
176
+
177
+ ---
178
+
179
+ ## 迭代器類型 / Iterator Types
180
+
181
+ ### ITSIterator
182
+
183
+ **Iterator 類型**
184
+
185
+ ```typescript
186
+ const iterator: ITSIterator<string> = {
187
+ next() { return { done: false, value: 'test' }; }
188
+ };
189
+ ```
190
+
191
+ ---
192
+
193
+ ### ITSIteratorResult
194
+
195
+ **IteratorResult 類型**
196
+
197
+ ```typescript
198
+ const result: ITSIteratorResult<string> = { done: false, value: 'test' };
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Proxy 類型 / Proxy Types
204
+
205
+ ### ITSProxify
206
+
207
+ **將物件的屬性包裝為 Proxy**
208
+
209
+ 將每個屬性轉換為具有 getter 和 setter 的物件。
210
+
211
+ ```typescript
212
+ interface User { name: string; age: number; }
213
+ type ProxifiedUser = ITSProxify<User>;
214
+ // type ProxifiedUser = {
215
+ // name: { get(): string; set(v: string): void };
216
+ // age: { get(): number; set(v: number): void };
217
+ // }
218
+ ```
@@ -0,0 +1,200 @@
1
+ # 內建類型 / Built-in Types
2
+
3
+ ## 概述 / Overview
4
+
5
+ 重新導出 TypeScript 內建類型,並提供包裝類型以增強 IDE 識別能力。
6
+
7
+ Re-exports TypeScript built-in types and provides wrapper types to enhance IDE recognition.
8
+
9
+ ## 來源 / Source
10
+
11
+ - [`lib/_build-in.ts`](../lib/_build-in.ts)
12
+
13
+ ---
14
+
15
+ ## 類型列表 / Type List
16
+
17
+ ### ITSParameters
18
+
19
+ **取得函數的參數類型**
20
+
21
+ 取得函數參數的元組類型。
22
+
23
+ ```typescript
24
+ function greet(name: string, age: number): string {
25
+ return `Hello, ${name}! You are ${age} years old.`;
26
+ }
27
+
28
+ type GreetParams = ITSParameters<typeof greet>;
29
+ // type GreetParams = [name: string, age: number]
30
+ ```
31
+
32
+ ---
33
+
34
+ ### ITSConstructorParameters
35
+
36
+ **取得建構函數的參數類型**
37
+
38
+ 取得建構函數參數的元組類型。
39
+
40
+ ```typescript
41
+ class User {
42
+ constructor(name: string, age: number) {}
43
+ }
44
+
45
+ type UserConstructorParams = ITSConstructorParameters<typeof User>;
46
+ // type UserConstructorParams = [name: string, age: number]
47
+ ```
48
+
49
+ ---
50
+
51
+ ### ITSPartial
52
+
53
+ **將類型的所有屬性設為可選**
54
+
55
+ ```typescript
56
+ interface User {
57
+ name: string;
58
+ age: number;
59
+ }
60
+
61
+ type PartialUser = ITSPartial<User>;
62
+ // type PartialUser = { name?: string; age?: number; }
63
+ ```
64
+
65
+ ---
66
+
67
+ ### ITSPick
68
+
69
+ **從類型 T 中選取指定的屬性 K**
70
+
71
+ ```typescript
72
+ interface User {
73
+ name: string;
74
+ age: number;
75
+ email: string;
76
+ }
77
+
78
+ type UserName = ITSPick<User, 'name'>;
79
+ // type UserName = { name: string; }
80
+ ```
81
+
82
+ ---
83
+
84
+ ### ITSInstanceType
85
+
86
+ **取得建構函數實例的類型**
87
+
88
+ ```typescript
89
+ class User {
90
+ name: string;
91
+ }
92
+
93
+ type UserInstance = ITSInstanceType<typeof User>;
94
+ // type UserInstance = User
95
+ ```
96
+
97
+ ---
98
+
99
+ ### ITSClassDecorator
100
+
101
+ **類別裝飾器類型**
102
+
103
+ ```typescript
104
+ type MyClassDecorator = ITSClassDecorator;
105
+ // type MyClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
106
+ ```
107
+
108
+ ---
109
+
110
+ ### ITSPropertyDecorator
111
+
112
+ **屬性裝飾器類型**
113
+
114
+ ```typescript
115
+ type MyPropertyDecorator = ITSPropertyDecorator;
116
+ // type MyPropertyDecorator = (target: object, propertyKey: string | symbol) => void;
117
+ ```
118
+
119
+ ---
120
+
121
+ ### ITSMethodDecorator
122
+
123
+ **方法裝飾器類型**
124
+
125
+ ```typescript
126
+ type MyMethodDecorator = ITSMethodDecorator;
127
+ // type MyMethodDecorator = <T>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
128
+ ```
129
+
130
+ ---
131
+
132
+ ### ITSParameterDecorator
133
+
134
+ **參數裝飾器類型**
135
+
136
+ ```typescript
137
+ type MyParameterDecorator = ITSParameterDecorator;
138
+ // type MyParameterDecorator = (target: object, propertyKey: string | symbol, parameterIndex: number) => void;
139
+ ```
140
+
141
+ ---
142
+
143
+ ### ITSNonNullable
144
+
145
+ **從 T 中排除 null 和 undefined**
146
+
147
+ ```typescript
148
+ type NullableString = string | null | undefined;
149
+ type NonNullString = ITSNonNullable<NullableString>;
150
+ // type NonNullString = string
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 裝飾器使用範例 / Decorator Usage Examples
156
+
157
+ ### 類別裝飾器
158
+
159
+ ```typescript
160
+ function LogClass(target: any): any {
161
+ console.log(`Class ${target.name} was defined`);
162
+ return target;
163
+ }
164
+
165
+ const MyDecorator: ITSClassDecorator = LogClass;
166
+
167
+ @MyDecorator
168
+ class MyClass {}
169
+ ```
170
+
171
+ ### 屬性裝飾器
172
+
173
+ ```typescript
174
+ function LogProperty(target: any, propertyKey: string | symbol): void {
175
+ console.log(`Property ${String(propertyKey)} was accessed`);
176
+ }
177
+
178
+ class MyClass {
179
+ @LogProperty
180
+ myProperty: string;
181
+ }
182
+ ```
183
+
184
+ ### 方法裝飾器
185
+
186
+ ```typescript
187
+ function LogMethod(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> {
188
+ const originalMethod = descriptor.value;
189
+ descriptor.value = function(...args: any[]) {
190
+ console.log(`Method ${String(propertyKey)} called with args:`, args);
191
+ return originalMethod.apply(this, args);
192
+ };
193
+ return descriptor;
194
+ }
195
+
196
+ class MyClass {
197
+ @LogMethod
198
+ myMethod() {}
199
+ }
200
+ ```