- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在初始实现后,我在终端 ng serve my-app of 中输入了数千个此错误,但我无法解决它。当我在 typescript 的 Angular 内遇到这样的问题时,这是我第一次
错误如下所示:
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.
[...]
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' });
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();
}
...
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));
}
}
最佳答案
在 "skipLibCheck": true
中设置 tsconfig.json
解决了我的问题
"compilerOptions": {
"skipLibCheck": true
}
关于angular - TS1086 : An accessor cannot be declared in ambient context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60092642/
我是一名优秀的程序员,十分优秀!