Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

object type factories #874

Closed
harrysolovay opened this issue Apr 11, 2023 · 0 comments · Fixed by #882
Closed

object type factories #874

harrysolovay opened this issue Apr 11, 2023 · 0 comments · Fixed by #882
Assignees

Comments

@harrysolovay
Copy link
Contributor

Every object type should overlap a factory. One can use the type modifier should they only want the TS type.

- import { CollectionConfig } from "@capi/rococo-dev/westmint"
+ import { type CollectionConfig } from "@capi/rococo-dev/westmint"

Let's consider the NFTs pallet usage.

Nfts.create({
  config: Rune.rec({
    settings: DefaultCollectionSetting.AllOff,
    mintSettings: Rune.rec({
      mintType: MintType.Issuer(),
      defaultItemSettings: DefaultItemSetting.AllOn,
    }),
  }),
  admin: alexa.address,
})

There's no autocompletion inside of Rune.rec. Yes, one gets a type error should they supply invalid fields, but that's not a great DX.

The alternative:

Nfts.create({
  config: CollectionConfig({
    settings: DefaultCollectionSetting.AllOff,
    mintSettings: MintSettings({
      mintType: MintType.Issuer(),
      defaultItemSettings: DefaultItemSetting.AllOn,
    }),
  }),
  admin: alexa.address,
})

This requires one import the CollectionConfig and MintSettings types/factories. However, the experience ends up being much smoother and more closely resembles the Rust equivalent. Also, we can in most cases forgo importing Rune.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant