Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError with native private properties #3322

Closed
2 of 4 tasks
rklos opened this issue Feb 27, 2025 · 3 comments
Closed
2 of 4 tasks

SyntaxError with native private properties #3322

rklos opened this issue Feb 27, 2025 · 3 comments

Comments

@rklos
Copy link
Contributor

rklos commented Feb 27, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I use native private properties inside my DB entity to prevent them from being exposed by accident to the users. It is needed because I also use typeorm's lifecycle decorators to run some logic eg. hashing password (and I need to store previous password inside the private property)

The nest's swagger plugin copies a transformed content of entities into _OPENAPI_METADATA_FACTORY static property, but it leaves private properties in their place.

The problem is that the whole app fails to run because private properties are allowed only inside classes but not in object literals.

Minimum reproduction code

https://github.com/rklos/nestjs-swagger-repro-repo

Steps to reproduce

  1. yarn
  2. yarn build
  3. yarn start:dev

Expected behavior

Private fields should be omitted when creating _OPENAPI_METADATA_FACTORY

Package version

11.0.5

NestJS version

11.0.9

Node.js version

22.14.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

/nestjs-swagger-repro-repo/dist/user.entity.js:34
        return { id: { required: true, type: () => Number }, username: { required: true, type: () => String }, email: { required: true, type: () => String, format: "email" }, password: { required: true, type: () => String }, isActive: { required: true, type: () => Boolean }, isAdmin: { required: true, type: () => Boolean }, #tempPassword: { required: true, type: () => String } };
                                                                                                                                                                                                                                                                                                                                      ^^^^^^^^^^^^^

SyntaxError: Unexpected identifier '#tempPassword'
    at wrapSafe (node:internal/modules/cjs/loader:1486:18)
    at Module._compile (node:internal/modules/cjs/loader:1528:20)
    at Object..js (node:internal/modules/cjs/loader:1706:10)
    at Module.load (node:internal/modules/cjs/loader:1289:32)
    at Function._load (node:internal/modules/cjs/loader:1108:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Module.require (node:internal/modules/cjs/loader:1311:12)
    at require (node:internal/modules/helpers:136:16)
    at Object.<anonymous> (/nestjs-swagger-repro-repo/src/app.service.ts:2:1)

Node.js v22.14.0

I cannot use @ApiHideProperty because of some Typescript's restrictions
Image

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this? You could use private as a temporary fix

@rklos
Copy link
Contributor Author

rklos commented Feb 27, 2025

@kamilmysliwiec I've just made a PR

@kamilmysliwiec
Copy link
Member

Let's track this here #3324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants