Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6394

Parameter of union type of enums?

$
0
0

What I have are two enums

enum Fruit { Apples, Oranges };enum Vegetable { Garlic, Cucumber };

and a type

type Food = Fruit | Vegetable;

Now I want to make another type that is a function and takes a food as a parameter

type OnViewFood = (food: Food) => void;

But when I do

viewFruit: OnViewFood = (fruit: Fruit) => `This is ${fruit}`;

I get an error that Food is not assignable to Fruit.How do I achieve my goal?


Viewing all articles
Browse latest Browse all 6394

Trending Articles