-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
strongly-typed decorators: infer return type of transform prop #12264
Comments
another thing that we could improve (probably not feasible):
it should error out at compiler time because of that |
I think we can add a second optional generic param on Reflector.createDecorator to describe the transformed value type as following:
|
I created a PR #12276 for this. |
Let's track this here #12276 |
Is there an existing issue for this?
Current behavior
The strongly-typed decorator factories introduced in #12237 are really cool. Thanks for adding them.
I noticed a small problem that comes up with a slightly advanced usage. Currently, the return type of
Refector.get(ReflectableDecorator<T>)
is typed as whateverReflectableDecorator<T>
was initialized as, usingReflector.createDecorator
. This is great for simple metadata storage, but if thetransform
method is used to alter the input value before it is stored, the return type does not update to match thetransform
method's return type.As an example:
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-yoxyxj?file=src%2Froles.guard.ts
Steps to reproduce
No response
Expected behavior
Ideally, the typing system would be able to detect the return value on the
transform
property, and use that as the return value of theRefector.get(ReflectableDecorator<T>)
method.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
10.2.1
Packages versions
[System Information]
OS Version : Windows 10
NodeJS Version : v18.16.0
PNPM Version : 8.6.12
[Nest CLI]
Nest CLI Version : 10.1.12
[Nest Platform Information]
platform-express version : 10.2.1
mapped-types version : 2.0.2
schematics version : 10.0.2
passport version : 10.0.1
graphql version : 12.0.8
testing version : 10.2.1
apollo version : 12.0.7
common version : 10.2.1
config version : 3.0.0
core version : 10.2.1
jwt version : 10.1.0
cli version : 10.1.12
Node.js version
18.16.0
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: