TS1086: Attempting to declare an accessor within an ambient context is not allowed

While using Angular, I encountered the error

TS1086: An accessor cannot be declared in an ambient context.
when using Javascript getters and setters in this Abstract Typescript class.

Here is the code snippet causing the issue:


  /**
   * 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 functionality was working perfectly until the recent update of Angular. Could it be that getters and setters are no longer allowed in Abstract classes?

Answer №1

This issue is not specific to Angular.

With the release of TypeScript 3.7, there was a significant change in how getters and setters are handled in type definition files.

It's important to note that TypeScript 3.7 emits get/set accessors in .d.ts files, which may cause compatibility issues for users on older versions like TypeScript 3.5 and earlier. However, those on version 3.6 should not be affected as it was prepared for this change.

More information here

If you're consuming type definitions generated with TypeScript 3.7 or newer, make sure you are using TypeScript 3.6 or higher to prevent any conflicts.

Answer №2

I encountered a similar issue with the google-auth-library.

While working on my Ubuntu system, I was using 'tsc' to convert my nodejs server from typescript to javascript. However, every time I ran 'tsc', I kept getting the 'TS1086: An accessor cannot be declared in an ambient context' error.

Initially, I tried updating typescript by running npm install typescript@latest within my server directory, but the errors persisted.

I realized that I needed to update my global version of typescript for 'tsc' to function properly. When I attempted to run npm install typescript@latest -g, I encountered more errors. Eventually, I had to remove the tsc link located in /usr/bin/.

To resolve this issue, here is what I did:

$ cd /usr/bin
$ sudo rm tsc
$ sudo npm install -g typescript@latest

Following these steps allowed me to successfully execute 'tsc' without encountering any errors.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for removing an item from an array using lodash

I have an array containing objects and I am looking to remove specific items based on certain conditions. Can someone guide me on how to achieve this using the lodash map function? Example: [{a: 1}, {a: 0}, {a: 9}, {a: -1}, {a: 'string'}, {a: 5 ...

Run Javascript code if a specific CSS class is present on an element

Whenever a user enters an incorrect value into a textbox on my page, an error message is displayed within a div with the class 'validation-errors'. I'm looking for a solution to trigger a javascript function (which adds a CSS property to a ...

Tips on integrating Codrops tutorial codes into a SilverStripe website project

Exploring the vast array of tutorials and code examples on the Codrops site has been an enlightening experience. Codrops Website I'm eager to incorporate some of these resources into my SilverStripe projects as well. SilverStripe CMS After learning h ...

Load data from a file into a dropdown menu using node.js

Exploring the realm of front end development on my own has been quite a challenge. I am currently struggling with the concept of populating a drop down box with data from a file. While utilizing node and JavaScript, I have decided to stick to these techn ...

Using the useState Hook: What is the best way to add a new item to the end of an array stored in the state

I'm currently working on a project using Next.js and Tailwind, where I am trying to populate an array using the useState Hook. My intention is to iterate through the array using the map function and add items to the end of the array until there are n ...

Getting Angular 2 and Ionic 2 to play nice together: is it worth the effort?

Recently, I attempted to create a glossary app using Ionic 2 and encountered numerous challenges when incorporating the http service. The Angular 2 tutorials had been updated, configuring the mock server proved difficult, and the Ionic 2 documentation offe ...

What is the significance of including the *dispatch* variable in the *dependency array* for the useEffect function?

While reviewing the source code of a ReactJS project, I noticed that the dispatch variable is included in the dependency array of the useEffect hook. Typically, I'm familiar with including useState() variables in this context, so I am curious about th ...

Is it possible to save the video title as a variable using YTDL-core?

Is there a way to store the video title as a global variable in JavaScript? ytdl.getBasicInfo(videoURL, function(err, info) { console.log(info.title) }); I have been trying various methods but I am unable to successfully define a variable to hold the v ...

Access the document on the desktop and open it in a new popup window

As a novice in html coding, I'm wondering if it's possible to write window size and other properties directly into the page. Let me explain. I'm currently working on a calculator and I want to run the HTML file on my desktop. Everything wor ...

Is there a way in jQuery to identify if a paragraph contains exactly one hyperlink and no other content?

I need to assign the 'solo' class to a link within a paragraph only if that link is the sole element in the paragraph. This example would have the 'solo' class: <p><a>I am alone</a></p> However, this example w ...

What could be causing my Ionic button to not initialize in the expected state while using ngIf with a boolean property connected to an Ionic checkbox?

I'm currently in the process of setting up a list of ingredients with checkboxes and conditional buttons, but I'm facing some challenges with the default state. Ideally, I only want the button to be visible when the checkbox is unchecked so that ...

Building a table in Quasar by utilizing nested objects

I am currently facing an issue while using Quasar to create Q-Tables. I am struggling with incorporating nested objects with dynamic key names. Below is the content of my table: data: [ { 'FrozenYogurt' : { &a ...

Tips for verifying a login modal on an asp.net webforms using jQuery?

I am currently working on an asp.net webpage that utilizes a modal bootstrap for user login. Upon clicking the Login button, it should authenticate the user and initiate a server-side method called "ExportToZip" to download a zip file. My issue lies in ens ...

Acquire the content of an interactive website with Python without using the onclick event

I am looking to extract the content of a dynamically generated website after clicking on a specific link. The link is structured as follows: <a onclick="function(); return false" href="#">Link</a> This setup prevents me from directly accessin ...

What is the best way to convert this jQuery code into an AngularJS implementation?

I'm diving into the world of AngularJS and looking for a more elegant solution using AngularJS principles Controller $scope.filter = function($event, active, id) { var html = ""; if(active){ $http({method: 'GET& ...

Utilizing Firebase login to integrate with Facebook API

My current setup involves Facebook authentication tied to login, all managed through Firebase. However, I now face the need to make an API call to Facebook using 'me/friends/' endpoint without having to send another request since I am already log ...

What is the best way to share information among Vue3 single file component instances?

I am seeking a way to have certain data in my single file component shared among all instances on the page, similar to how static variables work in PHP/C. To achieve this, I understand that in single file components, we declare data as a function like so: ...

Newbie in JavaScript seeking help with JSON indexing: What could be causing my script using (for ... in) to fail?

Not being a seasoned Javascript coder or very familiar with JSON, my approach may seem naive. Any recommendations for better solutions are appreciated. Below is the code I've written: <!DOCTYPE html> <html> <head> <script& ...

Javascript functions function properly only if they contain the 'alert()' command

My aim is to utilize Ajax (Javascript + php) for checking user name availability when a user moves focus to another form field. The strange part is that my functions only work when I include some alert(), without them, the functions fail to operate. Anoth ...

Difficulty altering value in dropdown using onChange function - Material-UI Select in React app

Having trouble updating dropdown values with MUI's Select component. The value doesn't change when I use the onChange handler, it always stays the same even after selecting a new item from the dropdown. I made a functional example on CodeSanbox. ...