Hi all,
First, some code to explain what I want:
class Character extends Schema {
@type([ Item ])
items: new ArraySchema<Item>();;
}
Imagine we have this character class. I want a character to be able to hold 0+ Item
s. An item would ideally be a superclass, with some subclasses, like this:
class Item extends Schema {
}
class Bucket extends Item {
}
class Hose extends Item {
}
What is the recommended way to do this? The problem with this approach is I would need some kind of client side check to determine which kind of item I'm holding. I'm also not sure this is possible at all, since the docs say "You can't mix types inside arrays." (here). If this was Rust for example, I'd probably have a bunch of items that impl an Item trait.
Another thing I would reach for in another language is enums. In Rust (again) for example you can have enums that have different values for each enum variant. This would be good for this case, as well as for representing optionals.
How have you managed to do this kind of thing? Would you just have n properties, one for each type of item?
As a related point, imagine also I want it to be possible for it to just be 0 or 1. I see there are no optionals, how would I do this? Do you just use an ArraySchema for this?
Thanks!