Is there a way to initialize an instance of a class with an object literal that doesn't contain all the elements in the class, but those present are part of the class?
class Example{
text:string;
number:number;
displayResult(){return this.text + this.number;}
}
let example=new Example;
example={text:"hello",number:12}; // error, displayResult() is missing in the object literal
What is the correct method for assigning values while still utilizing TypeScript's validations?
example=Object.assign(example,{text:"hello",numberrr:12});
This approach could work, however it bypasses validation for input fields - notice 'numberrr' which is incorrect but still passed through.