【发布时间】:2018-05-14 08:39:12
【问题描述】:
我在定义类型和检查该类型中是否包含值时遇到问题。
这是我的例子:
这些是类型:
export type Key = 'features' | 'special';
export type TabTypes = 'info' | 'features' | 'special' | 'stars';
当用户更改选项卡时,它会发送来自 TabTypes 类型的字符串值。
activeTabChanged(event: TabTypes) {
this.activeTab: TabTypes = event;
// it won't let me set the key here because key has a different type
// but the send event can be contained in type Key
// how can I check if the send event from type TabTypes is contained in type Key
this.key: Key = event;
}
是否有一种打字稿方法来检查具有类型的发送值是否可以等于来自不同类型的值?
【问题讨论】:
标签: typescript types