I want to declare a type for an array that can contain maximum one of the following strings: 'first', 'second', 'third'.
Some valid examples of how that array could be:
[]
[ 'first' ]
[ 'first', 'second' ]
[ 'first', 'second', 'third' ]
[ 'first', 'third' ]
[ 'second', 'third' ]
The types I've wrote:
export enum MyOptions {
first = 'first',
second = 'second',
third = 'third'
}
export type MyType = {
name: string;
email: string;
listings: {
MyOptions;
}[];
};
It has a warning saying Member 'MyOptions' implicitly has an 'any' type, but a better type may be inferred from usage.
So if it is changed to:
export type MyType = {
name: string;
email: string;
listings: {
options: MyOptions;
}[];
};
Now, there is no warning but it has that extra options value that I don't think it must be added.
Any ways to fix this?