I have an enum of string values. I want to pass a string value to enum and get the value from it.
export enum OperationType {
CREATE = "CREATE",
UPDATE = "UPDATE"
}
I have class as well
class Item {
type:string;
id:string
date:string
}
Now i am calling below function
function sendData(type:OperationType) {
//Do some work
}
Now i want to pass the value in enum like this but i am not able to do
//Here item.type = "CREATE"
sendData(OperationType[item.type])
But this is now allowed i get compile time error of wrong type. Please tell me how can i achieve?
EDIT: Error is
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof OperationType'.