Skip to content

Commit

Permalink
docs(codec): avoid repeating type declare (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
homura authored Jun 23, 2022
1 parent 4329413 commit b2e9f66
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/codec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ graph TD;
import { struct, Uint8, Uint128 } from "@ckb-lumos/codec";

// udt-info.mol
// table UDTInfo {
// struct UDTInfo {
// total_supply: Uint128,
// decimals: Uint8,
// }
Expand Down Expand Up @@ -187,3 +187,23 @@ table OmniLockWitnessLock {
```

![](./assets/suggest-trigger.gif)

## Works with TypeScript

### Get Type Definition from Value

```ts
import { molecule } from "@ckb-lumos/codec";
import type { UnpackResult } from "@ckb-lumos/codec";

const { struct } = molecule;

const RGB = struct(
{ r: Uint8, g: Uint8, b: Uint8 },
["r", "g", "b"] // order of the keys needs to be consistent with the schema
);

// We don't need to repeat the definition like this
// type UnpackedRGB = { r: number; g: number; b: number };
type UnpackedRGB = UnpackResult<typeof RGB>;
```

1 comment on commit b2e9f66

@vercel
Copy link

@vercel vercel bot commented on b2e9f66 Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lumos-website – ./

lumos-website-cryptape.vercel.app
lumos-website-git-develop-cryptape.vercel.app
lumos-website.vercel.app

Please sign in to comment.