Exploring the world of decorators in Typescript has led me to encounter a simple issue. Let's say I have a custom decorator named RetainType
and a class structured like this:
class Person {
@RetainType name: string;
@RetainType age: number;
@RetainType dateOfBirth: Date;
}
I wish to write it this way:
@RetainType class Person {
name: string;
age: number;
dateOfBirth: Date;
}
In essence, is there a method to apply a decorator to all properties within a class? The purpose of using @RetainType
is to generate metadata about each property (specifically design:type). Having a more streamlined approach instead of individually annotating every field would be advantageous.