I'm starting to think there is no easy solution for what I want to do. I have a class that takes in 10 parameters, most of them are optional. For simplicity reasons I will depict my issue using only 3 parameters.
I want my to be able to call the PageConfig Constructor omitting some or all of the optional parameters. e.g
new PageConfig({getList: this.getList})
new PageConfig({getList: this.getList, canDelete: false });
new PageConfig({getList: this.getList, isSliding: true });
I've tried to do this the following way.
export class PageConfigArgs {
canDelete?: boolean;
isSliding?: boolean;
getList: (pagingInfo: PagingInfo) => Observable<any>;
}
export class PageConfig extends PageConfigArgs {
constructor({
isSliding = false,
canDelete = true
}: PageConfigArgs) {}
}
Since getList is required it doesn't have a default in the constructor.
but the issue is I don't know how to reference getList from the constructor to assign it to the internal one.
How can I create a new configuration class mixing optional and required parameters?
Edit My main focus is to create easy initialization which doesn't require me to configure the configuration class after initialization.
Edit Closed as duplicate, I didn't realize I needed to declare all of the properties I wanted in the config inside my class. See previous question for resolution