Nest: RangeError: Maximum call stack size exceeded on using TypeScript accessors in services

Created on 21 Apr 2020  路  1Comment  路  Source: nestjs/nest

Bug Report

Current behavior

When using Typescript accessors in service getter method, getting RangeError

image

Input Code

Issue happening in TasksService file. Repo link below
https://github.com/Suedo/NestJS/tree/errors_demo/src/tasks

@Injectable()
export class TasksService {

  // underscore private value, and `get` accessor causing RangeError
  private _tasks: string[] = []; 

  get tasks(): string[] {
    return this.tasks;
  }

  // this block works fine
  // private tasks: string[] = [];
  // getAllTasks() {
  //   return this.tasks;
  // }
}

Expected behavior

I expected the typescript accessor method to work fiine

Possible Solution

Environment

Giving my versions from package.json (full file part of repo mentioned above, direct link)


    "@nestjs/common": "^7.0.0",
    "@nestjs/core": "^7.0.0",
    "@nestjs/platform-express": "^7.0.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4"

For Tooling issues:
- Node version: v12.16.1  
- Platform:  Mac OSX 10.15.2 

Others:

needs triage

Most helpful comment

private _tasks: string[] = []; 

get tasks(): string[] {
  return this.tasks; // should be this_tasks;
}

>All comments

private _tasks: string[] = []; 

get tasks(): string[] {
  return this.tasks; // should be this_tasks;
}
Was this page helpful?
0 / 5 - 0 ratings