Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$.exactUnion #158

Open
harrysolovay opened this issue Apr 22, 2023 · 0 comments
Open

$.exactUnion #158

harrysolovay opened this issue Apr 22, 2023 · 0 comments

Comments

@harrysolovay
Copy link
Contributor

While an all-encompassing union codec (such as that described in #152) might be excessive, we may benefit from an $.exactUnion codec, which would be used to describe exact discriminated unions.

const $a = $.object(
  $.field("a", $.str),
  $.optionalField("b", $.never),
)

const $b = $.object(
  $.optionalField("a", $.never),
  $.field("b", $.u8),
)

const $c = $.exactUnion(
  $.variant("a", $a),
  $.variant("b", $b),
)

type C = $.Input<typeof $c>
// {
//   a: string
//   b?: never
// } | {
//   a?: never
//   b: number
// }

This would useful should we wish to describe Capi's config with a SCALE codec (which would allow us to validate the config). See paritytech/capi#924.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant