It seems like finding a simple solution for my task is proving to be quite challenging. I have a class that accepts 10 parameters, most of which are optional. To simplify things, I will illustrate my dilemma using just 3 parameters.
I wish to be able to instantiate the PageConfig Constructor without having to include all optional parameters. For example:
new PageConfig({getList: this.getList})
new PageConfig({getList: this.getList, canDelete: false });
new PageConfig({getList: this.getList, isSliding: true });
I attempted the following approach.
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 mandatory, it does not have a default value in the constructor.
However, the challenge lies in referencing getList from the constructor to assign it internally.
How can I create a new configuration class that combines optional and required parameters?
Edit My primary goal is to establish a straightforward initialization process that eliminates the need to configure the class further post-instantiation.
Edit Marked as duplicate, I was unaware that I needed to declare all desired properties within the config class. Refer to previous question for resolution