Back to questionsWhich type does the name
JuniorTheoryCommon
Which type does the name Size stand for?
const sizes = ["S", "M"] as const;
type Size = (typeof sizes)[number];"M" | "S"
- Expecting the tuple
readonly ["S", "M"]: that istypeof sizesitself, and[number]takes the type of any one element, which gives the union"M" | "S". - Expecting
string: thanks toas constthe elements keep their literal types, so the element type is"M" | "S", notstring.
- How would
Sizechange if you added"L"to the array? - Why does the same trick give
stringonceas constis removed?