There is a common pattern in JavaScript whereby a "constructor" accepts an optional options object. Additionally, that options object may contain only the options the caller wishes to override. For example:
function Foo(options) {
this._options = {
foo: 'bar',
answer: 42,
amethod: function(){}
};
this._options = Object.assign(this._options, options);
}
let foo1 = new Foo();
foo2._options.foo; // 'bar'
foo1._options.answer; // 42
foo1._options.amethod(); // undefined
let foo2 = new Foo({answer: 0, amethod: function(a) { return a; }});
foo2._options.foo; // 'bar'
foo2._options.answer; // 0
foo2._options.amethod('foo'); // 'foo'
Is it possible to implement this pattern in Typescript? If so, how?