In the realm of custom libraries, it is impermissible to declare an accessor within an ambient context

I am working on a project with webpack and TypeScript (Project A) that generates a small library. This library is then utilized in an Angular 8 project (Project B).

In Project A, I define a class as follows:

export class Foo {

        private foo: string;

        constructor(foo: string) {
            this.foo = foo;
        }

    }

    export class Bar extends Foo {

        private bla: string;

        constructor(foo: string, bla: string) {
            super(foo);
            this.bla = bla;
        }

        get Bla(): string {
            return this.bla;
        }

    }

    

The build process is successful, but regardless of the TypeScript version I use, the Bla accessor always emits get Bla(): string in the corresponding .d.ts file.

However, when I include the package in my Angular project, I encounter the following error:

ERROR in ../node_modules/.../lib/types/src/.../.../xyz.d.ts:6:9 - error TS1086: An accessor cannot be declared in an ambient context.

    6     get Bla(): string;
    

Despite trying to update TypeScript to version 3.7 as suggested here, the issue persists.

It seems like the types generated for the accessor are not being created correctly. I would appreciate any insight into why this is happening and potential solutions.

Below is the tsconfig.json file for Project A:

{
      "compilerOptions": {
        "outDir": "lib/types",
        "declaration": true,
        "noImplicitAny": true,
        "module": "commonjs",
        "target": "es6",
        "noUnusedLocals": false
      },
      "exclude": [
        "node_modules",
        "lib",
        "tests"
      ]
    }
    

Dependencies for Project A:

  "devDependencies": {
        "@types/chai": "^4.2.5",
        "@types/gl-matrix": "^2.4.5",
        ...
      }
    

tsconfig.json for Project B:

{
      "compileOnSave": false,
      "compilerOptions": {
          ...
      }
    }
    

Dependencies for Project B:

  "dependencies": {
        "@angular/animations": "^8.2.14",
        ...
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "^0.803.19",
        ...
      }
    

If needed, I can also share the webpack configuration for Project A.

Answer №1

It appears that your issue is different from the one discussed in this linked question:

To resolve the problem, ensure that Project A is compiled using a version of TypeScript that is less than 3.7 (as Project B relies on older typing formats equal to or less than 3.6)

Answer №2

Resolution: Roll back codelyzer to version 4.5.0

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 invoking both next and error on an RxJS Observable

Suppose you have an API (such as GraphQL) that can gracefully handle failures by returning both data and error. Is there a way to trigger both the successful and error paths of an Observable? Service: public fetchData: Observable<any> { return ...

Integrate a service component into another service component by utilizing module exports

After diving into the nestjs docs and exploring hierarchical injection, I found myself struggling to properly implement it within my project. Currently, I have two crucial modules at play. AuthModule is responsible for importing the UserModule, which conta ...

Creating object types in typescript from object keys: a step-by-step guide

In my JavaScript object, I have two keys named foo and bar. const x = { foo: '', bar: '' } I also have a function called abc that takes a value (which can only be either foo or bar). function abc(value: string) { const selected = x[v ...

Exploring Angular's Implementation of D3 Force Simulation

Looking to incorporate a d3 force simulation in my Angular app. I have a run method that initializes and sets simulation options, as well as a ticked method that updates the simulation on each tick. However, I've encountered a few problems with this s ...

Minimizing assets in Angular 7 by running the command ng build --prod

After running ng build --prod, the JavaScript and CSS files located in /assets are not being minified. Is there a way to minify these files? I've checked the angular documentation but couldn't find any relevant information. ...

What is the process for converting an array of objects into an array of form groups?

I am looking to utilize the array function of the formbuilder to handle formcontrol arrays. I have a custom object array that I need to integrate into a FormArray, but it seems to only accept FormGroup as arguments. How can I convert my array of custom obj ...

transmit data from Node.js Express to Angular application

I am making a request to an OTP API from my Node.js application. The goal is to pass the response from the OTP API to my Angular app. Here is how the API service looks on Angular: sendOtp(params): Observable<any> { return this.apiService.post(&q ...

Troubleshooting date errors in react-datepicker using hookstate and Next.js

Exploring a page in the realm of nextjs: import type { NextPage } from "next"; import DatePicker from "react-datepicker"; import { useState as useStateHook } from "@hookstate/core"; import { useState as useStateReact } from &q ...

Angular does not alter the focus when a new component is loaded

Currently, I am working on resolving an accessibility issue with a screen reader in an Angular2 web application. When componentA (code shown below as Before) is loaded in Chrome, the entire browser window gains focus and the screen reader narrator announce ...

Is it possible for Angular to handle multiple routes for one path?

To create a landing page for anonymous users and an inbox for authenticated users without relying on manual navigation or path changes, I attempted to set up multiple components associated with the root path. However, my routing block did not work as plann ...

Attempting to adhere to the prescribed Cypress tutorial is resulting in various errors related to being "compiled under '--isolatedModules'"

I am new to using Cypress and I have been following the helpful tutorial on testing your first application. However, I have encountered some compiler issues in the third section. Following the instructions, I created a custom command but I am receiving th ...

Learn how to host a singular instance of an Angular application for every unique route, similar to the setup utilized in meet.jit.si

Is there a way to create an Angular app that loads a new instance of itself on every route/url? For example, visiting http://happy-app.com/happy would show the app in one state, and going to http://happy-app.com/happier would load the same app in a differe ...

Updating the navigation bar in Node/Angular 2 and displaying the sidebar once the user has logged in

I am facing a challenge with my first project/application built using Angular 2, particularly related to the login functionality. Here is what I expect from the application: Expectations: When I load the login component for the first time, the navbar ...

Why aren't special methods/mixins for Sequelize associations being generated?

According to the documentation available at https://sequelize.org/docs/v6/core-concepts/assocs/#special-methodsmixins-added-to-instances: When establishing an association between two models, special methods are introduced that enable instances of those mo ...

react-router: The 'history' type is not found in the current context

Here is some code snippet from App.tsx: interface AppProps{ history: any } export default class App extends React.Component<AppProps,...> { public state = { target: this.props.history.push('/') }; private route() { if (! ...

Accessing results from geocoder.geocode is restricted to local variables only

I need to extract longitude and latitude coordinates from google.maps.GeocodeResults in order to store them in an external Array<any>. Currently, I am able to display results[0], but encounter an OVER_QUERY_LIMIT error when attempting to add it to t ...

Tips for adjusting the height of a Mat-Card element within an Angular Material design component

I am currently working on an Angular 5 app and have implemented the following code which generates a sequence of mat-cards as shown in the image below using *ngFor. However, I am facing an issue where all the mat-cards have the same height as the first mat ...

Using TypeScript without specifying a specific argument in the any type

My function accesses local/session storage, but there is a condition that it can only be called if the window is defined. This function takes a generic args argument which I simplified to have a type of any[]. While using the useSessionStorage function, ...

Create dynamic breadcrumb trails using router paths

I am currently working on developing a streamlined breadcrumbs path for my application. My goal is to achieve this with the least amount of code possible. To accomplish this, I have implemented a method of listening to router events and extracting data fr ...

Transmit information to firebase using HttpClient

Seeking assistance on updating Firebase data (Realtime Database) in a specific table without overwriting it. The current code I have is causing the table [TB_MyProfile_Composite] to be overwritten instead of updated. Here is the code snippet for updating ...