【发布时间】:2017-05-15 05:59:50
【问题描述】:
我正在尝试通过创建掷骰子来学习 TypeScript (2.1)。我想我会使用元组来匹配带有图片的侧面。例如,如果我掷出 1(使用我计划实现的随机数生成器),我会得到一个圆圈的表示。
class D6 {
values: [number, string];
values = [1, "Circle"];
}
但是,仅使用那一点代码,我就会收到此错误:
Subsequent variable declarations must have the same type. Variable 'values' must be of type '[number, string]', but here has type '(string | number)[]'.
是否可以在 TypeScript 的类中使用元组?
【问题讨论】:
-
你可能想使用更接近对象的东西stackoverflow.com/questions/12787781/…
标签: typescript