nest: 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 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

-  get size(): Size;
+  size: Size;

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

export declare class HttpService {
   //...
   get axiosRef(): AxiosInstance;
}

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.

export declare class HttpService {
   //...
-   get axiosRef(): AxiosInstance;
+   axiosRef(): AxiosInstance;
}

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


Nest version: 6.10.1 -> 6.10.4

For Tooling issues:
- Node version: 12.13.1
- TypeScript version: 3.7.2
- Platform:  Windows

Others:

The errors I get are the following

node_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:16:9 - error TS1086: An accessor cannot be declared in an ambient context.
16     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<any>[];
           ~~~~~

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<Injectable>>;
           ~~~~~~~~~

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<Module>;
           ~~~~~~~

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<Module>;
           ~~~~~~~~~~~~~~

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<Injectable>>;
           ~~~~~~~~~~

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<Controller>>;
           ~~~~~~

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<Injectable>>;
           ~~~~~~~~~~~

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<Controller>>;
           ~~~~~~~~~~~

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<any>;
           ~~~~~~~~

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

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:

rm -r node_modules; rm package-lock.json
npm install

It sounds like a breaking change introduced in TypeScript https://github.com/microsoft/TypeScript/issues/33939