【发布时间】:2018-06-07 07:44:04
【问题描述】:
我有两个枚举
enum Fruit { Apples, Oranges };
enum Vegetable { Garlic, Cucumber };
和类型
type Food = Fruit | Vegetable;
现在我想制作另一种类型,它是一个函数,并以食物为参数
type OnViewFood = (food: Food) => void;
但是当我这样做时
viewFruit: OnViewFood = (fruit: Fruit) => `This is ${fruit}`;
我收到一个错误,即 Food 不能分配给 Fruit。 如何实现我的目标?
【问题讨论】:
标签: typescript react-native enums union