【发布时间】:2018-05-12 18:24:47
【问题描述】:
阅读reference。
而不是使用常量变量声明,
const directionUp: symbol = Symbol();
const directionDown: symbol = Symbol();
const directionLeft: symbol = Symbol();
const directionRight: symbol = Symbol();
在下面的代码中使用枚举类型,
enum Direction {
Up = Symbol(),
Down = Symbol(),
Left = Symbol(),
Right = Symbol(),
}
如何解决以下错误?
$ tsc --version
Version 2.8.3
$ tsc
tstut.ts(2,10): error TS2322: Type 'symbol' is not assignable to type 'Direction'.
tstut.ts(3,12): error TS2322: Type 'symbol' is not assignable to type 'Direction'.
tstut.ts(4,12): error TS2322: Type 'symbol' is not assignable to type 'Direction'.
tstut.ts(5,13): error TS2322: Type 'symbol' is not assignable to type 'Direction'.
【问题讨论】:
-
enum中是否允许使用符号? -
这是无效的。只需使用
consts