Error ts1086 an accessor cannot be declared in an ambient context

Regression Potential Commit/PR that introduced the regression** I don't know what introduced this issue, the only thing I found is this Stack Overflow question which says this so presumably seq...

Facing this issue when adding @nestjs/ng-universal to Angular 8 project.
Have tried with latest Nestjs version 6.10.9 and with Typescript 3.5.3. I am not able to upgrade typescript to newer version, Angular CLI does not support > 3.6.0

Application starts up normal but errors persists.

`10% building 3/3 modules 0 activenode_modules/@nestjs/common/http/http.service.d.ts:13:9 — error TS1086: An accessor cannot be declared in an ambient context.

13 get axiosRef(): AxiosInstance;
~~~~~~~~

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:21:9 — error TS1086: An accessor cannot be declared in an ambient context.

21 set httpAdapter(httpAdapter: T);
~~~~~~~~~~~

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:28:9 — error TS1086: An accessor cannot be declared in an ambient context.

28 get httpAdapter(): T;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/container.d.ts:18:9 — error TS1086: An accessor cannot be declared in an ambient context.

18 get applicationConfig(): ApplicationConfig | undefined;
~~~~~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:32:9 — error TS1086: An accessor cannot be declared in an ambient context.

32 get id(): string;
~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:33:9 — error TS1086: An accessor cannot be declared in an ambient context.

33 set instance(value: T);
~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:34:9 — error TS1086: An accessor cannot be declared in an ambient context.

34 get instance(): T;
~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:35:9 — error TS1086: An accessor cannot be declared in an ambient context.

35 get isNotMetatype(): boolean;
~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:36:9 — error TS1086: An accessor cannot be declared in an ambient context.

36 get isTransient(): boolean;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:20:9 — error TS1086: An accessor cannot be declared in an ambient context.

20 get id(): string;
~~

node_modules/@nestjs/core/injector/module.d.ts:21:9 — error TS1086: An accessor cannot be declared in an ambient context.

21 get scope(): Type[];
~~~~~

node_modules/@nestjs/core/injector/module.d.ts:22:9 — error TS1086: An accessor cannot be declared in an ambient context.

22 get providers(): Map<any, InstanceWrapper>;
~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:23:9 — error TS1086: An accessor cannot be declared in an ambient context.

23 get imports(): Set;
~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:27:9 — error TS1086: An accessor cannot be declared in an ambient context.

27 get relatedModules(): Set;
~~~~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:31:9 — error TS1086: An accessor cannot be declared in an ambient context.

31 get components(): Map<string, InstanceWrapper>;
~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:35:9 — error TS1086: An accessor cannot be declared in an ambient context.

35 get routes(): Map<string, InstanceWrapper>;
~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:36:9 — error TS1086: An accessor cannot be declared in an ambient context.

36 get injectables(): Map<string, InstanceWrapper>;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:37:9 — error TS1086: An accessor cannot be declared in an ambient context.

37 get controllers(): Map<string, InstanceWrapper>;
~~~~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:38:9 — error TS1086: An accessor cannot be declared in an ambient context.

38 get exports(): Set<string | symbol>;
~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:39:9 — error TS1086: An accessor cannot be declared in an ambient context.

39 get instance(): NestModule;
~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:40:9 — error TS1086: An accessor cannot be declared in an ambient context.

40 get metatype(): Type;
~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:41:9 — error TS1086: An accessor cannot be declared in an ambient context.

41 get distance(): number;
~~~~~~~~

node_modules/@nestjs/core/injector/module.d.ts:42:9 — error TS1086: An accessor cannot be declared in an ambient context.

42 set distance(value: number);
~~~~~~~~

[21:58:20] Found 23 errors. Watching for file changes.`

An accessor cannot be declared in an ambient context. #3513

Comments

ghiscoding commented Nov 30, 2019 •

Regression

Potential Commit/PR that introduced the regression**

I don’t know what introduced this issue, the only thing I found is this Stack Overflow question which says this

so presumably sequelize was compiled with typescript 3.7 and emits definition files that previous versions don’t understand. So you’ll need to upgrade to typescript 3.7 or use an earlier version of sequelize.

But I’m already using TypeScript version 3.7.2 , so I’m not sure where this error comes from and how to fix it.

Describe the regression

I get a bunch of TypeScript lint errors after updating to latest NestJS 6.10.4 (from 6.10.1 ). I tried going back to

6.10.1 but I still get the error. I tried upgrading my NodeJS version 10 to 12 but still have the same issue. I also tried using TypeScript version 3.6.3 instead of 3.7.2 but still the issue persist.

I found this bugfix in another library, which removes the get prefix in *.d.ts files, the change is that lib is the following

If I click and follow the link on the first @nestjs/common/http/http.service.d.ts:13:9 error, I do see the get in that d.ts file

So it seems that the d.ts Type files are not compiled properly? If I manually remove the get from axiosRef(): AxiosInstance; , I get 1 less error. So that seems to be the issue.

After manually editing every d.ts file causing errors and removing their get/set I’m back to working again, so that seems to be the issue.

Input Code

Expected behavior/code

Environment

The errors I get are the following

The text was updated successfully, but these errors were encountered:

ghiscoding commented Nov 30, 2019 •

Also if it helps, here is my tsconfig.json file

kamilmysliwiec commented Dec 1, 2019

Please, provide a minimal repository which reproduces your issue.

ghiscoding commented Dec 1, 2019

I tried replicating the issue on my other desktop and it was all working, however I had to install NestJS CLI because it was never installed on that computer. That made me think to update the CLI on the computer I had issue with. and after updating to latest NestJS CLI, the error is gone.

Since I can’t replicate after updating NestJS CLI, I’ll close the issue
Thanks

kotuadam commented Dec 1, 2019

I am having the same problem. Fresh install and updating cli does not solve it. Operating system is Mac OS

ghiscoding commented Dec 2, 2019

@kotuadam
There’s couple things you can try, the first one is to delete the entire node_modules and also the yarn/npm lock files, then re-install everything. The other options would be to see which TypeScript version you’re using, I’m on 3.7.2 which is the latest.

syukirah commented Dec 2, 2019

I’m also facing the same problem. Its working in my local but failed when i deploy to server (openshift)

Figments commented Dec 2, 2019

Same issue here.

whitebyte commented Dec 2, 2019

This issue is relevant, please reopen. I just encountered the same error while trying to update from 6.7.2 to 6.10.4. Managed to resolve it somehow after wiping node_modules and doing npm upgrade , but no idea how to reproduce it.

kamilmysliwiec commented Dec 2, 2019

It sounds like a breaking change introduced in TypeScript microsoft/TypeScript#33939

jeffminsungkim commented Dec 2, 2019

Currently using Typescript v3.5.1

Figments commented Dec 2, 2019

Switching entirely to Yarn seems to have fixed the issue for me, though the reason why NPM seemed to be the cause of my specific issues is beyond me.

franzos commented Dec 2, 2019

I’ve been able to resolve this, by manually upgrading typescript.

package.json : «typescript»: «3.4.3» to «typescript»: «3.7.2»

finally, cleared out, and re-installed everything:

kamilmysliwiec commented Dec 2, 2019

I’ve published v6.10.5 release with a downgraded TypeScript to 3.6.4 version. If you are facing this issue, please, update to the latest version of @nestjs . Hopefully, TypeScript team will solve this shortly

kotuadam commented Dec 2, 2019

latest push fixed everything for me

ghost commented Dec 10, 2019

Facing this issue when adding @nestjs/ng-universal to Angular 8 project.
Have tried with latest Nestjs version 6.10.9 and with Typescript 3.5.3. I am not able to upgrade typescript to newer version, Angular CLI does not support > 3.6.0

Application starts up normal but errors persists.

`10% building 3/3 modules 0 activenode_modules/@nestjs/common/http/http.service.d.ts:13:9 — error TS1086: An accessor cannot be declared in an ambient context.

13 get axiosRef(): AxiosInstance;

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:21:9 — error TS1086: An accessor cannot be declared in an ambient context.

21 set httpAdapter(httpAdapter: T);

node_modules/@nestjs/core/helpers/http-adapter-host.d.ts:28:9 — error TS1086: An accessor cannot be declared in an ambient context.

28 get httpAdapter(): T;

node_modules/@nestjs/core/injector/container.d.ts:18:9 — error TS1086: An accessor cannot be declared in an ambient context.

18 get applicationConfig(): ApplicationConfig | undefined;

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:32:9 — error TS1086: An accessor cannot be declared in an ambient context.

32 get id(): string;

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:33:9 — error TS1086: An accessor cannot be declared in an ambient context.

33 set instance(value: T);

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:34:9 — error TS1086: An accessor cannot be declared in an ambient context.

34 get instance(): T;

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:35:9 — error TS1086: An accessor cannot be declared in an ambient context.

35 get isNotMetatype(): boolean;

node_modules/@nestjs/core/injector/instance-wrapper.d.ts:36:9 — error TS1086: An accessor cannot be declared in an ambient context.

36 get isTransient(): boolean;

node_modules/@nestjs/core/injector/module.d.ts:20:9 — error TS1086: An accessor cannot be declared in an ambient context.

20 get id(): string;

node_modules/@nestjs/core/injector/module.d.ts:21:9 — error TS1086: An accessor cannot be declared in an ambient context.

21 get scope(): Type[];

node_modules/@nestjs/core/injector/module.d.ts:22:9 — error TS1086: An accessor cannot be declared in an ambient context.

22 get providers(): Map;

node_modules/@nestjs/core/injector/module.d.ts:23:9 — error TS1086: An accessor cannot be declared in an ambient context.

23 get imports(): Set;

node_modules/@nestjs/core/injector/module.d.ts:27:9 — error TS1086: An accessor cannot be declared in an ambient context.

27 get relatedModules(): Set;

node_modules/@nestjs/core/injector/module.d.ts:31:9 — error TS1086: An accessor cannot be declared in an ambient context.

31 get components(): Map ;

node_modules/@nestjs/core/injector/module.d.ts:35:9 — error TS1086: An accessor cannot be declared in an ambient context.

35 get routes(): Map ;

node_modules/@nestjs/core/injector/module.d.ts:36:9 — error TS1086: An accessor cannot be declared in an ambient context.

36 get injectables(): Map ;

node_modules/@nestjs/core/injector/module.d.ts:37:9 — error TS1086: An accessor cannot be declared in an ambient context.

37 get controllers(): Map ;

node_modules/@nestjs/core/injector/module.d.ts:38:9 — error TS1086: An accessor cannot be declared in an ambient context.

38 get exports(): Set ;

node_modules/@nestjs/core/injector/module.d.ts:39:9 — error TS1086: An accessor cannot be declared in an ambient context.

39 get instance(): NestModule;

node_modules/@nestjs/core/injector/module.d.ts:40:9 — error TS1086: An accessor cannot be declared in an ambient context.

40 get metatype(): Type;

node_modules/@nestjs/core/injector/module.d.ts:41:9 — error TS1086: An accessor cannot be declared in an ambient context.

41 get distance(): number;

node_modules/@nestjs/core/injector/module.d.ts:42:9 — error TS1086: An accessor cannot be declared in an ambient context.

42 set distance(value: number);

[21:58:20] Found 23 errors. Watching for file changes.`

Источник

An accessor cannot be declared in an ambient context. #714

Comments

unixxxx commented Apr 8, 2020

I am getting this error.

Angular 8,
Typescript 3.8.3

./node_modules/ngx-mask/lib/mask.service.d.ts:25:9 — error TS1086: An accessor cannot be declared in an ambient context.

25 set formElementProperty([name, value]: [string, string | boolean]);

The text was updated successfully, but these errors were encountered:

ColinMorris83 commented Apr 8, 2020

Angular 9.1 is the version that supports typescript 3.8, can you try updating your app to that.

unixxxx commented Apr 8, 2020

@ColinMorris83 I can’t update to angular 9, I installed Typescript@3.5.3 but the error remains

ColinMorris83 commented Apr 8, 2020

The library is built with typescript 3.8, therefore you’ll need to be on Angular 9 to use the latest version 9.0.0 of the library.

nedredmond commented Apr 9, 2020

Are there guidelines somewhere for what versions of ngx-mask are compatible with different Typescript/Angular versions? I am running Angular 7 with Typescript 3.2.2. is there a version of ngx-mask I can use?

Victor1993 commented Apr 27, 2020

I add to the doubt, is there any version that can be used with Angular 8 and Typescript 3.5.3?

thouseefrogers commented Apr 28, 2020

I also hit the same issue with Angular 8 and typescript 3.5.3.
The default version of ngx-mask that got installed was 9.0.2, I installed 8.2.0 and it compiled fine!!

Yass196 commented Apr 29, 2020

Hi, i had the same issue, i installed the 8.1.0 ngx-mask version for angular 8.2.14 and it works !
try to check the ngx-mask version history in [https://www.npmjs.com/package/ngx-mask]

vitorfiler commented May 27, 2020

O seguinte comando resolveu pra mim sem impactos no que eu estava usando:
npm install ngx-mask@8.0.0
cheguei a esta conclusão abrindo o package.json e vendo ngx-mask@9.0.2 instalada, ela não era compatível com a versão do meu projeto angular que é 8.0, por isso pensei em voltar e funcionou

thiagocall commented May 27, 2020

O seguinte comando resolveu pra mim sem impactos no que eu estava usando:
npm install ngx-mask@8.0.0
cheguei a esta conclusão abrindo o package.json e vendo ngx-mask@9.0.2 instalada, ela não era compatível com a versão do meu projeto angular que é 8.0, por isso pensei em voltar e funcionou

@vitorfiler, tentei fazer aqui. o erro saiu, no entanto, ainda dá erro quando declaro «export const options: Partial | (() => Partial)» no App.module.
Como você fez??

hitallow commented May 27, 2020

O seguinte comando resolveu pra mim sem impactos no que eu estava usando:
npm install ngx-mask@8.0.0
cheguei a esta conclusão abrindo o package.json e vendo ngx-mask@9.0.2 instalada, ela não era compatível com a versão do meu projeto angular que é 8.0, por isso pensei em voltar e funcionou

Valeu, isso funcionou para mim.

vitorfiler commented May 27, 2020

O seguinte comando resolvido para mim sem afetar o que você estava usando:
npm install ngx-mask@8.0.0, que
inicia esta conclusão abrindo o package.json e está vendo ngx-mask@9.0.2 aberto, ela não era compatível com uma versão do meu projeto angular que é 8.0, por isso pensei em voltar e funcionar

@vitorfiler , tentei fazer aqui . o erro saiu, no entanto, ainda dá erro quando declarar «exportar const opções: Parcial | (() => Parcial)» no App.module .
Como você fez ??

no meu caso, tive esse problema, por que instalei o ngx-mask no meu projeto angular sem dizer qual versão eu queria(npm install ngx-mask) logo ele instalou a versão mais atual, que não era compatível com a versão do angular que eu usava, por isso instalei outra manualmente, mas apagar a pasta node modules e baixar de novo, irá baixar a versão talvez mais recomendada ou compatível com o projeto automaticamente(funcionou pra um amigo meu).

hitallow commented May 27, 2020

O seguinte comando resolveu pra mim sem impactos no que eu estava usando:
npm install ngx-mask@8.0.0
cheguei a esta conclusão abrindo o package.json e vendo ngx-mask@9.0.2 instalada, ela não era compatível com a versão do meu projeto angular que é 8.0, por isso pensei em voltar e funcionou

@vitorfiler, tentei fazer aqui. o erro saiu, no entanto, ainda dá erro quando declaro «export const options: Partial | (() => Partial)» no App.module.
Como você fez??

Acho que o erro que dá, é porque você não está adicionando valor a constante. o exemplo com
export const options: Partial | (() => Partial) é apenas um exemplo de como você deve fazer para inserir as configurações no modulo. nesse caso, voce esta declarando uma constante, adicionando a tipagem, mas não está inserindo o valor.

Источник

An accessor cannot be declared in an ambient context. #3619

Comments

ghost commented Dec 11, 2019

Bug Report

Environment

node_modules/@nestjs/core/injector/module.d.ts:23:9 — error TS1086: An accessor cannot be declared in an ambient context. 23 get imports(): Set;

node_modules/@nestjs/core/injector/module.d.ts:27:9 — error TS1086: An accessor cannot be declared in an ambient context. 27 get relatedModules(): Set;

node_modules/@nestjs/core/injector/module.d.ts:31:9 — error TS1086: An accessor cannot be declared in an ambient context. 31 get components(): Map>;

node_modules/@nestjs/core/injector/module.d.ts:35:9 — error TS1086: An accessor cannot be declared in an ambient context. 35 get routes(): Map>;

node_modules/@nestjs/core/injector/module.d.ts:36:9 — error TS1086: An accessor cannot be declared in an ambient context. 36 get injectables(): Map>;

node_modules/@nestjs/core/injector/module.d.ts:37:9 — error TS1086: An accessor cannot be declared in an ambient context. 37 get controllers(): Map>;

node_modules/@nestjs/core/injector/module.d.ts:38:9 — error TS1086: An accessor cannot be declared in an ambient context. 38 get exports(): Set;

node_modules/@nestjs/core/injector/module.d.ts:39:9 — error TS1086: An accessor cannot be declared in an ambient context. 39 get instance(): NestModule;

node_modules/@nestjs/core/injector/module.d.ts:40:9 — error TS1086: An accessor cannot be declared in an ambient context. 40 get metatype(): Type;

node_modules/@nestjs/core/injector/module.d.ts:41:9 — error TS1086: An accessor cannot be declared in an ambient context. 41 get distance(): number;

node_modules/@nestjs/core/injector/module.d.ts:42:9 — error TS1086: An accessor cannot be declared in an ambient context. 42 set distance(value: number); `»>

The text was updated successfully, but these errors were encountered:

Источник

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.

Update 1

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));
    }
}

Понравилась статья? Поделить с друзьями:
  • Error trying to parse settings sublime text 3
  • Error trying to open unclosed connection
  • Error trying to find the directory for the game config file nfs hot pursuit
  • Error true undeclared first use in this function
  • Error truck data is missing trying to use a fallback truck