typescript - 打字稿运行时错误:无法读取未定义(枚举)的属性
问题描述
我在文件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”行上。
有人可以告诉我我做错了什么吗?
解决方案
我刚刚发现,如果你有循环导入,这也可能发生。
推荐阅读
- javascript - 在更改范围滑块时运行函数
- python - 在 fasttext 监督学习模型的背后发生了什么?
- jquery - jQuery.contextMenu 无法在 Safari 浏览器中识别 SVG 图像
- asp.net-core - 将数据传递给控制器的问题 - 更新数据
- javascript - 改变
- oop - 表示派生类上的“容器”是从基类的容器派生的设计模式
- android - 如何在android studio中快速保存多个位图
- excel - DAX 中的子级别计算总和 - Power Pivot
- javascript - 调整列表 (
- ) 按屏幕尺寸显示
- node.js - NestJS - 未加载 JWT 依赖项