I am new to typescript.I am working on a backed that uses Express, Node and Typescript. I have an object that has type:
interface Fruit {
FruitType: "Citrus" | "Melon" | "Tropical"
FruitName: string
}
I am creating a new instance of Fruit where I am reding the fruit type from JSON file and populating it
const config = readFromFile()
const myFruit:Fruit ={
FruitName: config.fruitName,
FruitType: config.fruitTYPE
}
This gives an error Type 'string' not assignable to type "Citrus" | "Melon" | "Tropical"
. I understand I am getting this error because I am assigning an unknown string instead of an Enum value. I am assuming the solution is to somehow check if the fruit type is one of the values before assigning it to the FruitType object. How do I fix this error?