In my class, I have a property member that is of type array. Each item in the array can be of various types such as MetaViewDatalinked or MetaViewContainer, as shown below
class MetaViewContainer{
children: (MetaViewDatalinked | MetaViewContainer)[];
}
class MetaViewDatalinked{
id: string;
}
I am looking to initialize the class with its properties using class-transformer (
plainToClass(MetaViewContainer, json)
).
If my class did not have an array property, like in the example below, I would use @Type
class MetaViewContainer{
@Type((typeHelpOptions: TypeHelpOptions) => {
if (typeHelpOptions.object.container)
return MetaViewContainer;
return MetaViewDatalinked;
})
child: MetaViewDatalinked | MetaViewContainer;
}
The problem arises when using @Type because it is called only once irrespective of whether the property is a single class or an array of classes, resulting in an array of one type (in case of an array property).
If you have any suggestions on how to resolve this issue, I would greatly appreciate it.