#Decorator function compilation error when injected in service

3 messages · Page 1 of 1 (latest)

craggy plume
#

hey all,

having issues setting up the following decorator, I did not like the idea of setting up a customer decorator and declaring service globally in order to access their functionalities. So I opted for something this.

@Injectable()
export class SendFCMNotificationService {
  constructor(private readonly someService: SomeService) {}

  static decoratorFn() {
    return createParamDecorator(async (data: any, ctx: ExecutionContext) => {
      const result = await ctx.switchToHttp().getResponse().send();
      // Wait for the controller function to finish before sending the notification
      await result;
    });
  }
}

which is then imported on a route level like so

 @HttpCode(HttpStatus.OK)
  @Get('test')
  @SendFCMNotificationService.decoratorFn()
  findJob() {
    return '1';
  }

the issue is I keep getting the following error, the error does not really care for the return type of the controller function, it just keep throwing the same error witch the TypedPropertyDescriptor being string, number, object, any, etc.

Decorator function return type 'ParameterDecorator' is not assignable to type 'void | TypedPropertyDescriptor<() => string>'

Not sure what is causing this, I've been at it for quite a while, any help would be much appreciated!

novel burrow
#

createParamDecorator is not meant to create a decorator that is to be used on class methods. It should be used to create a decorator used on route handler paramters

craggy plume
#

damn I see, big miss on my part, I suppose a follow up to the original question would be if an apporuch like this if considered "good" for notifications