File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ graph TD;
16
16
import { struct , Uint8 , Uint128 } from " @ckb-lumos/codec" ;
17
17
18
18
// udt-info.mol
19
- // table UDTInfo {
19
+ // struct UDTInfo {
20
20
// total_supply: Uint128,
21
21
// decimals: Uint8,
22
22
// }
@@ -187,3 +187,23 @@ table OmniLockWitnessLock {
187
187
```
188
188
189
189
![ ] ( ./assets/suggest-trigger.gif )
190
+
191
+ ## Works with TypeScript
192
+
193
+ ### Get Type Definition from Value
194
+
195
+ ``` ts
196
+ import { molecule } from " @ckb-lumos/codec" ;
197
+ import type { UnpackResult } from " @ckb-lumos/codec" ;
198
+
199
+ const { struct } = molecule ;
200
+
201
+ const RGB = struct (
202
+ { r: Uint8 , g: Uint8 , b: Uint8 },
203
+ [" r" , " g" , " b" ] // order of the keys needs to be consistent with the schema
204
+ );
205
+
206
+ // We don't need to repeat the definition like this
207
+ // type UnpackedRGB = { r: number; g: number; b: number };
208
+ type UnpackedRGB = UnpackResult <typeof RGB >;
209
+ ```
You can’t perform that action at this time.
0 commit comments