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.