Suppose I have an object that contains various roles, each granting a specific set of rights:
const allRoles = {
user: [
'right1'
],
admin: [
'right1',
'right2'
],
} as const
If I want to define the types for user rights and admin rights separately, I can use the following:
type userRights = Array<typeof allRoles.user[number]>
type adminRights = Array<typeof allRoles.admin[number]>
To represent both types combined, I would do:
type RoleRights = userRights | adminRights
However, if I want to create a single type declaration for all available rights without specifying individual user or admin rights, is there a way to achieve this?
It is similar to creating an array of all rights using:
const roleRights = new Map(Object.entries(allRoles))