This is a simplified example:
class PersonParms{
name:string;
lastName:string;
age?:number;
get fullName(){return this.name + " " + this.lastName;}
}
class Person{
constructor(prms:PersonParms){
}
}
new Person({name:'John',lastName:'Doe'}) // ts error: Property 'fullName' is missing in type '{ name: string; lastName: string; }'.
The idea is to pass a literal object as the intizalizer of PersonParms but having that getter you can neither declare the getter optional or add the property to the object literal. Is there another way to achieve it?
interface IPersonParms { name:string; lastName:string; age?:number; readonly fullName?: string; }
. Casting object literal to class doesn't seem to be useful - getter won't magically appear there anyway, you'll need to create an instance of aPersonParms
class. – Parlay