How to convert existing property decorator to a parameter decorator to work with property shorthand?

106 Views Asked by At

I want to use some property decorator (@Type from 'class-transformer' package) on a parameter, that is a property shorthand. Basically convert this:

class Test {
  @Type(() => SomeClassType)
  public prop1: SomeClassType;

  constructor(prop1: SomeClassType) {
    this.prop1 = prop1;
  }
}

Into this:

class Test {
  constructor(@Type(() => SomeClassType) public prop1: SomeClassType) {}
}

The problem is that decorator Type is only Property decorator, not a Property AND/OR Parameter decorator. So that I cannot use it directly on a parameter.

What is the easiest way to create a wrapper/adapter on a property decorator to make it work with parameter

(note: a parameter here is a shorthand property - public prop1: ...)

0

There are 0 best solutions below