This is a more simple example of what I'm trying to do:
export class Person{
id:Number;
name:String;
}
export class PersonForm{
// This line:
default:Person = {name: "Guy"};
// Gives the following error:
// Error:(25, 5) TS2322: Type '{ name: string; }' is not assignable to type 'Person'.
// Property 'id' is missing in type '{ name: string; }'.
// I tried <Person>{name: "Guy"} but it gives the same error.
}
How can I make the compiler ignore this issue as long as Im not using non existant properties, or how do I declare the class so I can do the assignment this way instead of new Person() and then setting just the properties I want.
Note: Sending an object with all the properties into the constructor is not the solution I'm expecting. Also using an interface works because I can declare the fields optional, how can I do the same in a class?
Adding some more info:
The main goal of what I'm trying to achieve:
Find the best way to declare a class (not an interface) so I can initialize it with clean code in one line setting only the parameters I want to set. In Java you would overload constructors or use the Builder pattern.
I could certainly try the builder pattern but I'm looking for a more typescript way to do it, if there's any.