【发布时间】:2018-10-26 04:42:38
【问题描述】:
我在文件RESTConfig.ts中有以下接口和枚举:
export const enum RESTMethod {
POST = "POST",
GET = "GET"
}
export interface RESTConfig {
url: string;
method: RESTMethod;
data: any;
}
我想像这样在另一个类中导入和使用枚举:
import { RESTConfig, RESTMethod } from './RESTConfig';
class Pipelines {
...
private someMethod() {
let rest: RESTConfig = {
url: "",
method: RESTMethod.POST,
data: {}
}
...
}
...
}
linting 和 transpiling 工作正常,但在运行时出现以下错误:
TypeError: 无法读取未定义的属性“POST”
在“方法:RESTMethod.POST”行上。
谁能告诉我我做错了什么?
【问题讨论】:
-
找到答案了吗?
-
使枚举不恒定 - 删除 'const' 术语
标签: typescript enums undefined