【发布时间】:2018-09-23 22:54:16
【问题描述】:
我是 Typescript 的新手,我不确定语法。我尝试在线搜索,但没有发现任何有用的信息。
这些是我的接口和枚举定义。
interface Products {
asian: {[key: string]: string};
american: {[key: string]: string};
}
enum State {
NEWYORK = 'nyc',
BOSTON = 'boston'
}
interface Branch {
nyc: {
products: Products;
};
boston: {
products: Products;
};
}
我不确定如何在Branch 接口中使用枚举State。这样我就可以使用STATE.NEWYORK 和STATE.BOSTON 枚举。
像这样的:
interface Branch {
State.NEWYORK: {
products: Products;
};
STATE.BOSTON: {
products: Products;
};
}
感谢阅读。
【问题讨论】:
-
不确定你的意思..你可以在类型状态的界面中定义一个字段,就像你可以为任何其他类型一样
-
@TitianCernicova-Dragomir 我更新了问题。我对语法感到困惑,我想在
Branch中使用 Enum 或确保该字段的类型为Enumnyc: State.NEWYORK
标签: typescript enums interface