typescript - 在 Typescript 的类声明中使用“declare”关键字的目的是什么?
问题描述
我在vscode源代码中看到了一些代码,并将其重写为一个简单的版本。
我想知道在下面的代码中使用声明的目的:
interface IDog {
readonly color: string
}
class Doggy {
public color = "";
}
class Doggy2 implements IDog {
//Here is the code as mentioned
declare readonly color: string;
}
const aaa = new Doggy()
const bbb = new Doggy2()
在编译的代码中,Doggy2类中的颜色被忽略了。这是declare的正常用法吗?我在哪里可以在 Typescript 中学习这些特殊代码?
解决方案
推荐阅读
- php - 检测没有前置字符的换行符
- jquery - 通过 jquery 在单个函数中触发更改和就绪事件
- mysql - 找到 avg() 后如何在最后添加空值行
- linux - 将 Linux 文件系统类型分配给变量
- javascript - 将本地文件与远程同步
- c# - 在将数据表导出到 excel 时,列中的十进制值(例如 5 然后 5.1、5.2)会创建一个新的整行并使 excel 工作表变得混乱
- sql - SQL如何求和总数量
- angular - 当返回的 JSON 与 Angular 服务中的类不完全匹配时,将 API 响应映射到类
- python - 如何获取序列化方法字段中的所有实例
- angular - Angular:如何传递后端数据,在 ngfor 中单击特定组件