typescript - const 变量声明是类型定义吗
问题描述
通过以下const
变量(Point
)的声明,
const Point = {
x: 1,
y: 2
}
Point.z = 6
说,Property 'z' does not exist on type '{ x: number; y: number; }'
const
变量声明是类型定义吗?
解决方案
不,TypeScript 会根据您将Point
变量设置为的类型推断类型。const
正在设置它,以便您无法重新分配Point
变量。var
您将在代码中使用or看到相同的行为let
。
推荐阅读
- python - 我如何知道调用当前函数的按钮的名称?
- tfs - 如何管理解决方案项目中的访问权限
- php - 如何使用数组中的对象(php)?
- python - 使用自定义用户模型在 django 的作者字段中自动添加用户名
- php - Laravel 5.8 自定义验证器解析器不工作
- docker - Docker(windows):docker container ls / docker image list突然什么也没显示
- python - Sympy矩阵中的浮点数而不是分数?
- c# - 如何使用图像的字节流在 C# 中通过 Slack-App 在 Slack 上上传图像
- c# - Rider 建议使用 C# 8 语法,但未能构建解决方案
- python - 我正在构建一个集成深度学习模型,它需要两个输入,当我连接它时会出错