seanpmaxwell / overnight

TypeScript decorators for the ExpressJS Server.
MIT License
878 stars 40 forks source link

Class constructor X cannot be invoked without 'new' #1

Closed nozzlegear closed 6 years ago

nozzlegear commented 6 years ago

Hey! I'm interested in trying out Overnight in a project, but I'm having trouble using it in a project that targets ES6/2015. When I create a controller class and use the @Controller("x/y/z") decorator, ts-node throws an error saying that Class constructor ClassName cannot be invoked without 'new'. If I remove the @Controller decorator the app will start up fine (but then, obviously, I lose the controller route).

After some digging around, I think this is happening because my project is targeting ES6, but Overnight is targeting ES5, and TypeScript can't extend an ES5 class. Once I switch my target to ES5 with the full es2015 lib everything starts to work again. I just wanted to check and confirm if this is intended, or if I'm goofing up somewhere.

seanpmaxwell commented 6 years ago

This is intended, if you open up the file tsconfig.base.json in the master repo, you can see that the target is "es5". I don't know if you're using a git pull or trying to download from npm, but if you really want to use "es6", download the master repo, and change the target to es6 at the master repo. Or you could just download /src/core, and add the "target" and "lib" key value pairs to tsconfig.json.

nozzlegear commented 6 years ago

Thanks! I've got it working without any issues just by switching my server target to es5 with the es2015 lib.

orenmizr commented 5 years ago

can you please explain that ? do i need to switch to es5 in order to use overnight ? node can understand higher syntax than that. what if a developer wants to avoid compiling to old version of the language.

avizmil commented 5 years ago

I still get the error. Does overnight support es6 ?

tboothman commented 5 years ago

This is pretty disappointing since I was looking forward to using this package. Surely everyone's using this within node, and every supported version of node supports es2015 (node 6 supports it too). Any chance of some movement on this, I'd rather not just copy/paste this library into my project.

seanpmaxwell commented 5 years ago

OvernightJS now supports es6. I closed this issue a while ago but after more requests to support es6 came in I made it to support es6.

tboothman commented 5 years ago

Awesome, thanks