-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Constructor parameter decorators should allow undefined
as the type of key
#10959
Comments
I just created a PR for this issue #10970 Also, on a side note, thank you (and the entire TypeScript team) for allowing us to keep using the original TS-decorators implementation in v5. Switching to the JS decorators (current proposal) would drastically degrade DX since it currently doesn't support param-based decorators + |
I found this issue #1667 that had the same errors as me, but the comments didn't help. I also found a different issue nestjs/nest#10959, and the fix they used nestjs/nest#10970, and used that to fix the problem with the InjectMetric decorator. The problem is that the decorator types are wrong. Record<string, unknown> fails with strict checks, and the key may also be undefined. Fixes #1667
Is there an existing issue for this?
Current behavior
TypeScript 5.0 introduces some tightening on decorator type-checking. This is basically a bug fix, but it affects any decorator used on constructor parameters.
Here, the decorator function returned by
Inject
says it takes astring | symbol
for itskey
parameter; however, if the usage above is supposed to be valid, then this declaration always been incorrect. Constructor parameters always receiveundefined
for theirkey
.TypeScript 5.0 enforces checking on this, and users of existing decorator libraries like NestJS will receive an error like the following:
More details are available on the TypeScript repo at microsoft/TypeScript#52435
Minimum reproduction code
https://www.typescriptlang.org/play?ts=5.0.0-dev.20230126#code/JYWwDg9gTgLgBAbzgSQHYCsCmBjeBfOAMyghDgCIABVTAZxnVoHptSQJVyBuAWACh+2ADYBDWrTgBhRPzhy4rVPSgBXXNAAUlNFlwaAyjCjBUAcwCURCBABccZSYuI8-PEA
Steps to reproduce
Try any example of
@Inject
on a constructor parameter withtypescript@next
.Expected behavior
Nest should update its declaration to allow
undefined
as a key type.Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
No response
Packages versions
9.2.1
Node.js version
No response
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: