I have an enumeration in my typescript code, which lists all possible user roles:
enum UserRole {
CONSULTANT,
MANAGER,
...
}
And I have a REST endpoint /users/id/roles that returns array of strings representing roles of a particular user:
[
"CONSULTANT",
"MANAGER",
...
]
Now I want to map this array in my frontend code. I tied doing it like this:
import {Http} from '@angular/http';
import {Observable} from "rxjs/Observable";
import {plainToClass} from "class-transformer";
...
getUserRoles(id: string): Observable<UserRole[]> {
return this.http.get(`/users/${id}/roles`)
.map(responce => plainToClass(UserRole, responce.json()));
}
But I get:
error TS2345: Argument of type 'typeof UserRole' is not assignable to parameter of type 'ClassType'. Type 'typeof UserRole' provides no match for the signature 'new (...args: any[]): UserRole[]'.
Q: Is there any way to convert string-array to array of enum elements?
Note: Im using Typescript 2.5.3. in pair with Angular 5.0.5.