'How to specify types for decorators

I want to specify a type of target to a decorator in typescript

const dec = <T>(...): PropertyDecorator => (target: T, propertyKey) => { ... };

class SomeClass {
  @dec() a: number;
}

And here the T type is unknown. I know I can specify it with generic directly with @dec<SomeClass>(), but in this case in the SomeClass @dec will always have <SomeClass>.

Is there a way to make TypeScript automatically understand what type @dec should have?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source