TS1086:无法在环境上下文中声明访问器 [英] TS1086: An accessor cannot be declared in an ambient context

查看:935
本文介绍了TS1086:无法在环境上下文中声明访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Angular运行时,出现TS1086: An accessor cannot be declared in an ambient context.,这是rel ="nofollow noreferrer >此Abstract Typescript类中的Javascript获取器和设置器..

When running with Angular, I'm getting thje error TS1086: An accessor cannot be declared in an ambient context. for Javascript getters and setters in this Abstract Typescript class.

这是来源:


  /**
   * 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都运行良好.我们不再允许在Abstract类中使用getter和setter吗?

This was working fine until the most recent version of Angular. Are we no longer allowed to use getters and setters in Abstract classes?

推荐答案

这不是Angular错误.

This isn't an Angular error.

TypeScript 3.7对类型定义文件中的getter和setter进行了重大更改.

TypeScript 3.7 introduced a breaking change for getters and setters in the type definition files.

如上所述,TypeScript 3.7在.d.ts文件中发出get/set访问器,这可能会导致消费者对3.5和更低版本的TypeScript的旧版本进行重大更改. TypeScript 3.6用户不会受到影响,因为该功能已针对该功能进行了过时验证.

As mentioned above, TypeScript 3.7 emits get/set accessors in .d.ts files which can cause breaking changes for consumers on older versions of TypeScript like 3.5 and prior. TypeScript 3.6 users will not be impacted, since that version was future-proofed for this feature.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#class-field-mitigations

如果要使用3.7或更高版本生成的类型定义,则应该使用TypeScript 3.6或更高版本.

You should be using TypeScript 3.6 or higher if you're going to consume type definitions generated with 3.7 or higher.

这篇关于TS1086:无法在环境上下文中声明访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆