-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support for union types #39
Comments
Currently metarpheus recognizes this pattern:
as describing an enumerated type To add support for union types, we can accept the more general case in which inside I'm ignoring type parameters for now, since we probably don't need them in many use cases. |
👍 it's fine to only infer enums when using the enumero syntax. All other cases should be union types. |
You probably already discussed this, but: if I got this correctly, it means that a type like e.g. Did you also discuss specific examples from real projects where the union types feature would have been useful? |
Yes, we discussed it with Gabro and @calippo, but it's just a first step – it doesn't seem too difficult to add type parameters later. I suppose types like As for examples, we've mostly talked about it with Claudio to use in tapiro to represent errors. But I think I had also run into a real use case in code where we had something like
where the value of |
A doubt: when we use in our model a tagged union sealed trait UnionExample
object UnionExample {
case class First(arg: String) extends UnionExample
case class Second(arg: String, anotherArg: String) extends UnionExample
} are we interested in using This could influence whether to put Currently in my PR:
Some possibilities:
If we care about them as separate types we might want 2, or just keep the current state. But it's probably important that we have just one type definition in TypeScript. What do you think about that? I'd lean more towards keeping it as it is currently and by convention never using |
I suppose we will mainly access Are we losing any information not having them as stand-alone case classes? |
I don't think we lose any information in doing so, we can just record it all in the members of the tagged union. I think this can be a first step, we can evaluate later whether we're interested in using the subtypes like |
Metarpheus should support union types such as:
Also opened buildo/metarpheus-io-ts#79 to add the generation to
metarpheus-io-ts
The text was updated successfully, but these errors were encountered: