Back to questionsWhich type does TypeScript infer for
JuniorTheoryCommon
Which type does TypeScript infer for sizes?
const sizes = ["S", "M"] as const;readonly ["S", "M"]
- Expecting
as constonly to addreadonly: it also keeps each literal type, so the elements stay"S"and"M", notstring. - Expecting an array of the union
"M" | "S":as constalso fixes the length and the order, so the result is a tuple.
- What does tsc report for the call
sizes.push("L")? - Which type would
sizesget withoutas const, and why?