问题描述
在最初的实现中,在终端ng中输入my-app后,我有成千上万个这样的错误,但我无法解决.这是我的第一次,当我在打字稿中遇到这样的问题时错误看起来像这样:
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 typescriptErrors looks like this:
24 protected get parentElement(): HTMLElement | null;
~~~~~~~~~~~~~
../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:26:19
-错误TS1086:无法在环境上下文中声明访问器.
- 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
-错误TS1086:无法在环境上下文中声明访问器.
- 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
-错误TS1086:无法在环境上下文中声明访问器.
- 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
-错误TS1086:无法在环境上下文中声明访问器. [...]
- 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:
143 this.fileService.add({isFolder:true,name:folder.name, 父:this.currentRoot? this.currentRoot.id:'root'});
143 this.fileService.add({ isFolder: true, name: folder.name, parent: this.currentRoot ? this.currentRoot.id : 'root' });
代码如下:
main.component.ts:
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:
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));
}
}
推荐答案
在tsconfig.json
中设置"skipLibCheck": true
解决了我的问题
Setting "skipLibCheck": true
in tsconfig.json
solved my problem
"compilerOptions": {
"skipLibCheck": true
}
这篇关于TS1086:无法在环境上下文中声明访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!