I am creating an interface in which I need a property to be explicitly set to a value when it's used.
I have seen I can specify multiple possible values for a property
e.g.
propertyA: 'x' | 'y' | 'z';
Would this work for single value?
So if I did something like:
propertyA: 'x'
When the interface gets used to define an object somewhere else, would the compiler complain if a different value was attempted to be used.
Is there a way in my example above, I can say this property can only ever hold a value of 'x'?
I came across type
's and wondered if this could be a better way for me to achieve this rather than an interface.
Please correct me if I have misunderstood something here.