Open
Description
Description
Let's say I have a User
class with a constructor that requires a parameter.
The example is completely dummy.
class User {
name: string;
isAdmin: boolean;
constructor (whiteLabelClient: Client) {
this.isAdmin = whiteLabelClient.priority > 5
}
}
From what I understand in the code base, it is not possible to pass any argument to the constructor when we use plainToClass
.
A current workaround is to update the plain object like we want and only after deserialise it.
Proposed solution
It would be really helpful for me to be able to pass this constructor arguments from the plainToClass
method like so:
plainToClass(User, userObj, {}, whiteLabelClient)
So the signature would be something like this
function plainToClass<T, V>(cls: ClassConstructor<T>, plain: V, options?: ClassTransformOptions, ...constructorArguments: any[]): T;