Imagine that you're developing a developer community forum site using TypeScript. The available user roles in this forum are admin, moderator, and user. Each user role should have an array of string values representing their permissions, as follows:
const userPermissions: UserPermissions = {
admin: ['createCategory', 'updateCategory', 'deleteCategory', 'createPost', 'updatePost', 'deletePost'],
moderator: ['createPost', 'updatePost', 'deletePost'],
user: ['createPost', 'readPost', 'commentOnPost', 'upvotePost', 'downvotePost'],
};Define the
UserPermissionstype alias to represent the possible user roles in the forum. These roles are:'admin','moderator', and'user'in string format, as indicated by the keys of theuserPermissionsobject.Create the
UserPermissionstype alias as an object type. It must have properties with keys that match the user roles ('admin','moderator', and'user'), and the values of these properties must be arrays of strings representing the permissions for each role.
Hint
When defining the UserPermissions type, you don't need to explicitly list all the permissions for each role. Instead, just specify that each key (representing a user role) will map to an array of strings (representing the permissions).