TS1086: An accessor cannot be declared in an ambient context

18,988

This isn't an Angular error.

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

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

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

Share:
18,988

Related videos on Youtube

Ole
Author by

Ole

Updated on June 04, 2022

Comments

  • Ole
    Ole almost 2 years

    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.

    This is the source:

    
      /**
       * 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
      }
    

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

  • Ole
    Ole over 4 years
    OK so I need to make sure Angular is using the latest version of Typescript?
  • Reactgular
    Reactgular over 4 years
    @Ole it depends which version of Angular you're running, because you can only upgrade to the highest version supported by that version of Angular. It's possible to disable the TypeScript version restriction on Angular, but I can not say if that is a stable thing to do.
  • Ole
    Ole over 4 years
    Ah - I tried bumping Typescript only, and Angular wants it kept between versions 3.4.0 and 3.6.0. Do you know if theres a command we can run to update everything in one snap?
  • Reactgular
    Reactgular over 4 years
    @Ole it depends what version of Angular you are running, but the Angular CLI now has an upgrade tool. I'd make sure you can rollback changes before you do any upgrade. angular.io/cli/update