I am wondering if it is possible to define an array of unique types based on a union of those types.
Let's say I have the following type Value
:
type Value = string | number
Then, I attempted to create a type called Values
like this:
type Values = Value[]
However, this results in a type:
type Values = (string|number)[]
Is there a way for me to achieve something like this, based on the Value
type?
type Values = string[] | number[]
This is because I need to render checkboxes for table filters in my function. These checkboxes will always have either a string
or a number
as their value.
When you click on a checkbox, it adds that value to an array. For instance, if you are filtering by the column firstName
and add two names to the filter, it would result in an array of string
s or an array of number
s, represented by the type Values
: string[] | number[]
.
So, is there a way to derive the Values
type from the Value
type?
I have set up a sample sandbox for comparing these types. Any insights would be greatly appreciated!