When you create a parameter decorator, the arguments that it can accept aren't strongly typed. For example take this code snippet from the docs https://docs.nestjs.com/custom-decorators
import { createParamDecorator } from '@nestjs/common';
export const User = createParamDecorator((data: string, req) => {
return data ? req.user && req.user[data] : req.user;
});
When using the @User()
decorator I can pass any argument to it, it doesn't validate that its a string.
Example @User(100)
should be invalid but its not.
It would be nice to get a more strongly typed decorator for examples where you want to pass an options object and have intellisense on it.
Good idea. Would you like to create a PR?
Sure thing I can give it a go!
I've tackled this today, should work on it some more over the weekend. At this point i've made possible to define the typing through generics.
You guys think this is a cool approach for a v1 ?
EDIT:
i've created an repo with some working examples: https://github.com/galesky/nestjstypeddecorators
you should find them on the app.controller.ts
This is quite crucial if it wants to be actually used...
PS: Current workaround:
export const QueryFields: (...dataOrPipes: [] | [FieldsListOptions]) => ParameterDecorator = createParamDecorator
Fixed in 6.11.0
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I've tackled this today, should work on it some more over the weekend. At this point i've made possible to define the typing through generics.
You guys think this is a cool approach for a v1 ?
EDIT:
i've created an repo with some working examples: https://github.com/galesky/nestjstypeddecorators
you should find them on the
app.controller.ts