Skip to content

TS error when creating a variant (discrimated union) dynamically #569

Answered by fabian-hiller
NixBiks asked this question in Q&A
Discussion options

You must be logged in to vote

The problem is that variant currently requires that you specify at least two options (otherwise variant makes no sense), but TS is not smart enough to know that the return type of Object.entries(attributes).map(...) will have two elements. It is just typed as a generic array of object schemas instead of a tuple.

I can consider changing the types of variant so that TS does not complain. But this has two drawbacks. The first is that TS will stop complaining if you define variant with no or only one option. The second is that it will require us to add additional code that slightly increases the bundle size to return an issue if no option (empty array) is specified.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@NixBiks
Comment options

@fabian-hiller
Comment options

Answer selected by NixBiks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants