Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  49] [ 7]  / answers: 1 / hits: 20624  / 5 Years ago, fri, december 27, 2019, 12:00:00

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?


More From » angular

 Answers
1

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.


[#51356] Friday, December 13, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mitchellg

Total Points: 235
Total Questions: 117
Total Answers: 106

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;