I have a thousands of this error after initial implementation nad typing in terminal ng serve my-app of and i can't resolve it. This is first time for me when i have problem like this inside angular with typescript Errors looks like this:
ERROR in ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:24:19 - error TS1086: An accessor cannot be declared in an ambient context.
24 protected get parentElement(): HTMLElement | null; ~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:26:19
- error TS1086: An accessor cannot be declared in an ambient context.
26 protected get nativeElement(): HTMLElement; ~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:28:9
- error TS1086: An accessor cannot be declared in an ambient context.
28 get activatedValue(): string; ~~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:29:9
- error TS1086: An accessor cannot be declared in an ambient context.
29 set activatedValue(value: string); ~~~~~~~~~~~~~~ ../../node_modules/@angular/flex-layout/core/typings/breakpoints/break-point-registry.d.ts:20:9
- error TS1086: An accessor cannot be declared in an ambient context.
[...]
Does somebody know a reason? I can't test my app until I fix it.
Okay, i make it forward. Most of errors is gone, but i have few ones now, for example first of them:
ERROR in src/app/main/main.component.ts:143:63 - error TS2322: Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
143 this.fileService.add({ isFolder: true, name: folder.name, parent: this.currentRoot ? this.currentRoot.id : 'root' });
Code looks like this:
main.component.ts:
currentRoot: MpFileElement = new MpFileElement();
...
addFolder(folder: { name: string }) {
this.fileService.add({ isFolder: true, name: folder.name, parent:
this.currentRoot ? this.currentRoot.id : 'root' });
this.updateFileElementQuery();
}
...
file.service.ts:
import { Injectable } from '@angular/core';
import { v4 } from 'uuid';
import { MpFileElement } from '../models/mp-file-element.model';
import { Observable } from 'rxjs/internal/Observable';
import { BehaviorSubject } from 'rxjs';
export interface IFileService {
add(fileElement: MpFileElement);
delete(id: string);
update(id: string, update: Partial<MpFileElement>);
queryInFolder(folderId: string): Observable<MpFileElement[]>;
get(id: string): MpFileElement;
}
@Injectable()
export class MpFileService implements IFileService {
constructor() {}
private map = new Map<string, MpFileElement>()
private querySubject: BehaviorSubject<MpFileElement[]>;
add(fileElement: MpFileElement) {
fileElement.id = v4();
this.map.set(fileElement.id, this.clone(fileElement));
return fileElement;
}
delete(id: string) {
this.map.delete(id);
}
update(id: string, update: Partial<MpFileElement>) {
let element = this.map.get(id);
element = Object.assign(element, update);
this.map.set(element.id, element);
}
queryInFolder(folderId: string) {
const result: MpFileElement[] = [];
this.map.forEach(element => {
if (element.parent === folderId) {
result.push(this.clone(element));
}
})
if (!this.querySubject) {
this.querySubject = new BehaviorSubject(result);
} else {
this.querySubject.next(result);
}
return this.querySubject.asObservable();
}
get(id: string) {
return this.map.get(id);
}
clone(element: MpFileElement) {
return JSON.parse(JSON.stringify(element));
}
}
Setting "skipLibCheck": true
in tsconfig.json
solved my problem
"compilerOptions": {
"skipLibCheck": true
}
I had this same issue, and these 2 commands saved my life. My underlying problem is that I am always messing up with global install and local install. Maybe you are facing a similar issue, and hopefully running these commands will solve your problem too.
ng update --next @angular/cli --force
npm install typescript@latest
If it's just a library that's causing this, this will avoid the problem just fine. Typescript can be a pain on the neck sometimes so set this value on your tsconfig.json file.
"compilerOptions": {
"skipLibCheck": true
}
I got the same issue when adding @angular/flex-layout to my Angular 8 project now with
`npm install @angular/flex-layout --save`.
This since now that command installed the major 9th version of the flex-layout package. Instead of upgrading everything else to the last version, I solved it by installing the last 8th major version of the package instead.
npm install @angular/[email protected] --save
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With