javascript - TS1086:无法在环境上下文中声明访问器
问题描述
使用 Angular 运行时,我在此 Abstract Typescript 类中遇到 Javascript getter 和 setter错误TS1086: An accessor cannot be declared in an ambient context.
。
这是来源:
/**
* The current id key for the EStore instance.
* @return this.config.idKey;
*/
get ID_KEY(): string {
return this.config.idKey
}
/**
* The current guid key for the EStore instance.
* @return this.config.guidKey;
*/
get GUID_KEY(): string {
return this.config.guidKey
}
在最新版本的 Angular 之前,这一切正常。我们是否不再允许在抽象类中使用 getter 和 setter?
解决方案
这不是 Angular 错误。
TypeScript 3.7 对类型定义文件中的 getter 和 setter 进行了重大更改。
如上所述,TypeScript 3.7 会在 .d.ts 文件中发出 get/set 访问器,这可能会导致消费者对旧版本的 TypeScript(如 3.5 和更早版本)进行重大更改。TypeScript 3.6 用户不会受到影响,因为该版本已针对此功能进行了面向未来的验证。
如果您要使用 3.7 或更高版本生成的类型定义,则应该使用 TypeScript 3.6 或更高版本。
推荐阅读
- java - 由于 XML 元数据标记,XML 未得到解析
- linux - Tp-Link T2600G-28TS GPL 源代码编译错误
- laravel - laravel 中 where 条件的数组
- visual-studio - 如何将 nuget 包推送到 Azure Artifacts?
- sql - 按日期名称或日期 ID 获取当年的计数天数
- php - phpmailer 不工作,错误日志:未捕获 PHPMailer\PHPMailer\Exception:SMTP 错误:无法连接到 SMTP 主机
- amazon-web-services - 获取 AWS 免费套餐的账单,我已将其用于学习目的
- python - 带逗号的列表推导语法
- css - CSS 字体系列
- html - 拉伸图像