FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

TypeError: Class constructor SocialPost cannot be invoked without 'new' #1208

Closed mallaaravind closed 11 months ago

mallaaravind commented 1 year ago

Version of FoalTS: 3.1.0

Hi,

I tried implementing https://foalts.org/docs/common/validation-and-sanitization#with-a-validation-class-class-validator in my foal project and I see the following error when I run my code.

[3:31:35 PM] Starting compilation in watch mode...

TypeError: Class constructor SocialPost cannot be invoked without 'new'
    at /Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/common/validation/validate-body.hook.js:35:65
    at getApiCompleteOperation (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/openapi/metadata-getters/get-api-complete-operation.js:48:77)
    at makeControllerRoutes (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/routes/make-controller-routes.js:144:75)
    at makeControllerRoutes.next (<anonymous>)
    at makeControllerRoutes (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/routes/make-controller-routes.js:130:57)
    at makeControllerRoutes.next (<anonymous>)
    at makeControllerRoutes (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/routes/make-controller-routes.js:130:57)
    at makeControllerRoutes.next (<anonymous>)
    at createApp (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/express/create-app.js:85:24)
    at main (/Users/aravind/git-repo/myFoalProject/src/index.ts:17:28)
Program node ./build/index.js exited with code 1

[3:31:38 PM] Found 0 errors. Watching for file changes.

restarting child
Starting child process with 'node ./build/index.js'
TypeError: Class constructor SocialPost cannot be invoked without 'new'
    at /Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/common/validation/validate-body.hook.js:35:65
    at getApiCompleteOperation (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/openapi/metadata-getters/get-api-complete-operation.js:48:77)
    at makeControllerRoutes (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/routes/make-controller-routes.js:144:75)
    at makeControllerRoutes.next (<anonymous>)
    at makeControllerRoutes (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/routes/make-controller-routes.js:130:57)
    at makeControllerRoutes.next (<anonymous>)
    at makeControllerRoutes (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/core/routes/make-controller-routes.js:130:57)
    at makeControllerRoutes.next (<anonymous>)
    at createApp (/Users/aravind/git-repo/myFoalProject/node_modules/@foal/core/lib/express/create-app.js:85:24)
    at main (/Users/aravind/git-repo/myFoalProject/src/index.ts:17:28)
Program node ./build/index.js exited with code 1

Is there any issue with FoalTS documentation? or framework? or am I missing something.

Thank you

LoicPoullain commented 1 year ago

Hi 👋

What version of class-validator do you use?

Could you share the code of SocialPost and the code that calls the hook?

LoicPoullain commented 11 months ago

I'm closing this issue as there has been no response to the last comment. Feel free to re-open it if you still need help on this 👍