In my Angular application, I have an HTTP service that returns the allowed accesses for a specific user. The response structure is as shown below:-
{
"accessId": 4209318492034,
"folderPath": "data/sample_folder/",
"permissions": [
"READ",
"WRITE"
]
}
The permissions field in the response is an array containing only two strings - "READ"
(mandatory) and "WRITE"
(optional). It may or may not include the WRITE permission.
To type this response using an interface and ensure that only certain strings are accepted in the permissions array, I defined an Enum like so:-
enum Permissions {
READ = 'READ',
WRITE = 'WRITE'
}
However, when I try to use this Enum in the UserAccess interface for the response, it doesn't seem to work as intended:-
export interface UserAccess {
accessId: string;
folderPath: string;
permissions: Permissions[]
}
How can I enforce that the permissions array strictly includes values from the specified Permissions enum?