Closed hywax closed 2 months ago
This is a fault of Typescript, because when import type
is used, the resulting compiled JavaScript doesn't have the import of the original type, as Typescript will strip the type imports, and then it will cause the metadata that Nest relies on to not be accurate/existent. There's nothing Nest can really do about this either, as it's a language feature, not a framework one.
It's important to note that while it looks like you're using the imported class as a type
, it's actually being used as a reference
when the metadata is properly set. You'd need to view the compiled JS to understand that though
Is there an existing issue for this?
Current behavior
Now there is a bug, when we do import type, then nest can't resolve dependencies. This is erroneous behavior because from a typescript point of view everything is correct, we are using the class as a type, not an instance.
If you write the code:
Then we get:
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-yejp4i?file=src%2Fapp.controller.ts
Steps to reproduce
No response
Expected behavior
There shouldn't be an error
Package
Other package
No response
NestJS version
No response
Packages versions
Node.js version
20.9.0
In which operating systems have you tested?
Other
No response