Exploring different roles for authorization:
['admin', 'manager', 'user']
Is there a way to create a specific type, named Roles
, which is essentially a string array ( string[]
) that is limited to only containing values from the list of roles mentioned above? It should also be able to be an empty array.
Edit: Here is my initial attempt at defining this:
type Roles = [] | ['user'] | ['manager'] | ['admin'] | ['user', 'manager'] | ['user', 'admin'] | ['manager', 'admin'] | ['user', 'manager', 'admin']
However, this structure does not allow for:
const roles:Roles = ['admin','user']
Furthermore, if there are 4 roles, it becomes cumbersome as the number of options increase exponentially and it does not support variations in position within the list.