I have an array:
const specialNumbers = [1, 10, 20, 50] as const; // type: readonly [1, 10, 20, 50]
I would like a type (ex: SpecialNumber
) that is the union of the values in the arrays.
For example to be used as:
const getSpecialNumber = (): SpecialNumber => { // SpecialNumber = 1 | 10 | 20 | 50
// ...
}
How to construct SpecialNumber
from specialNumbers
?
4
To get the union of the values, you can do:
type SpecialNumber = (typeof specialNumbers)[number];