I am attempting to easily transfer all the properties from an object in a constructor to a class's properties
type tCustomUpload = {
name : string,
relationship : string,
priority : number,
id : number
}
class CustomUpload {
name : string;
relationship : string;
priority : number;
id : number;
constructor (payload : tCustomUpload) {
Object.assign(this, payload);
}
}
I experimented with the solution on How to assign values to all properties of class in TypeScript?, but encountered 2 issues with that approach
- the interface contains optional properties, while I require them to be mandatory
- typescript raises errors for that solution stating something like
Property 'x' has no initializer and is not definitely assigned in the constructor.