Skip to content

Polymorphism in grammar rules #538

Answered by msujew
theogiraudet asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @theogiraudet,

It is intended behavior. Basically everytime your grammar rule looks like X: Y | Z | ...; (even when it's only X: Y;) it gets transformed into a type of type X = Y | Z | .... It doesn't really restrict the model, but it's probably non-obvious why:

When performing the union over different types, all common properties across them get pulled to the union type. If both A and B have a value property (and they do, since they inherit from the Value interface), the generated type from ValueRule: ARule | BRule also contains value, since both alternatives contain that type as well. In that sense, the type doesn't lose any information that it shouldn't know in the first place. In t…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@theogiraudet
Comment options

@msujew
Comment options

@theogiraudet
Comment options

Answer selected by theogiraudet
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