I have an HTTP service in Angular that returns the accesses allowed for a particular user. The sample response is as follows:-
{
"accessId": 4209318492034,
"folderPath": "data/sample_folder/",
"permissions": [
"READ",
"WRITE"
]
}
Specifically the permissions field is an array that will contain only the following strings, "READ"(compulsory) and "WRITE"(optional, may or may not be present).
I want to type this response using an interface, and for sake of enforcing the presence of only these strings in the permissions array, I created an Enum as follows:-
enum Permissions {
READ = 'READ',
WRITE = 'WRITE'
}
But using it in the interface for the response as follows does not work:-
export interface UserAccess {
accessId: string;
folderPath: string;
permissions: Permissions[]
}
How do I enforce that the permissions array will contain values ONLY from the defined Permissions string enum?