相关疑难解决方法(0)

使用字符串值创建枚举

以下代码可用于enum在TypeScript中创建:

enum e {
    hello = 1,
    world = 2
};
Run Code Online (Sandbox Code Playgroud)

并且可以通过以下方式访问这些值:

e.hello;
e.world;
Run Code Online (Sandbox Code Playgroud)

如何创建enum带字符串值?

enum e {
    hello = "hello", // error: cannot convert string to e
    world = "world"  // error 
};
Run Code Online (Sandbox Code Playgroud)

typescript

241
推荐指数
12
解决办法
18万
查看次数

标签 统计

typescript ×1