TS1086:无法在环境上下文中声明访问器 [英] TS1086: An accessor cannot be declared in ambient context

查看:102
本文介绍了TS1086:无法在环境上下文中声明访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最初的实现中,在终端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 typescript Errors looks like this:

错误 ../../node_modules/@angular/flex-layout/core/typings/base/base2.d.ts:24:19 -错误TS1086:无法在环境上下文中声明访问器.

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

-错误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:

src/app/main/main.component.ts中的

ERROR:ts:143:63-错误TS2322:类型 '字符串|未定义"不能分配给字符串"类型.类型 不能将'undefined'分配给'string'类型.

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, 父: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:无法在环境上下文中声明访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆