typescript - 如何在打字稿上声明类道具?
问题描述
这是来自火基地的代码:
class Fire {
...
}
Fire.shared = new Fire(); // error on .shared
export default Fire;
我得到的错误是
'typeof Fire' 类型上不存在'属性'shared'
我如何在打字稿中解决这个问题?
解决方案
You need use the keyword static
in front of the property name to declare them as class fields just like in a regular javascript
class Fire {
static shared: Fire = new Fire()
...
}
推荐阅读
- python - 过拟合——训练和验证准确率之间的巨大差异
- android - 无法实例化片段找不到片段构造函数android
- python - 在网站上请求后如何发送电报消息?
- r - 选择最高值和行均值的更快方法
- python - 多线程 Python 插入 Postgree
- resources - 列表中每个任务的不同资源分配
- java - 如何在套接字编程中将我的课程放在客户端中?
- c# - 如何在 C# 中查找多个变量 DateRanges 之间的间隙
- python - 将 Pyside-2 项目导入我由 Django 构建的网站
- javascript - 脚本文件未在 Safari 浏览器的 javascript 中加载