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

Unions of instances produce unhelpful error message #1194

Open
matthew-dean opened this issue Nov 13, 2023 · 0 comments
Open

Unions of instances produce unhelpful error message #1194

matthew-dean opened this issue Nov 13, 2023 · 0 comments

Comments

@matthew-dean
Copy link

Problem

If a struct contains an instance type

const Struct = type({
  condition: instance(Condition)
})
//...

...you get a helpful error message like:

Expected a `Condition` instance, but...

However, if you use a union:

const Struct = type({
  condition: union([instance(Condition), instance(Bool)])
})

...The error message ceases to have any usefulness, and outputs:

Expected the value to satisfy a union of `instance | instance`...

Possible Solutions

  1. Output a message like:
Expected the value to satisfy a union of `Condition | Bool`...
  1. Instead of leaving it up to Superstruct, allow customization of messages in the struct, like:
const Struct = type({
  condition: label(union([instance(Condition), instance(Bool)]), 'Condition | Bool')
})

...which could produce:

Expected the value to satisfy `Condition | Bool`, but...
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