Polymorphism in grammar rules #538
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Hi @theogiraudet, It is intended behavior. Basically everytime your grammar rule looks like When performing the union over different types, all common properties across them get pulled to the union type. If both I don't really see a good reason for returning interfaces instead of union types with that in mind. Do you think it restricts the modeling space? |
Beta Was this translation helpful? Give feedback.

Hi @theogiraudet,
It is intended behavior. Basically everytime your grammar rule looks like
X: Y | Z | ...;(even when it's onlyX: Y;) it gets transformed into a type oftype 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
AandBhave avalueproperty (and they do, since they inherit from theValueinterface), the generated type fromValueRule: ARule | BRulealso containsvalue, 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…