By "Or split type" I mean string | number | boolean
. If you have a better name, I'll update the question.
I'm working on an interface which contains a list of tags, similar to this:
type Tags = "big" | "small" | "sharp" | "dull";
interface Shape {
name: string;
tags: Tags[];
}
Later in the code, I'd like to list out all the possible tags. In my actual code, the amount of tags is far greater than four, so I want to use type assertion to make sure I list them all. How can I do this?
Two ways I can imagine are:
- Creating an array from an "or split type," which is impossible for obvious reasons (nested conditions).
- Asserting a type based off an array of strings. This one seems fairly possible, I know that
document.createElement("a" | "div" | "span"...)
does something magical with this, though I can't find the right keywords to figure out what it's called.
My ideal would be something along these lines:
// Not real code
const Tags = ["big", "small", "sharp", "dull"];
interface Shape {
name: string;
tags: Array<item in Tags>;
}
So, is there a way to make an array of strings act like an or split type?