Let's say I got this interface:
// IFoo.d.ts
export default interface IFoo {
foo: string;
bar: number;
}
and I use it here
// FooModel.ts
import IFoo from "./IFoo";
export default class FooModel implements IFoo {
foo = 'hello';
bar = 1;
constructor(_fooModel?: IFoo) {
if (_fooModel === undefined) return; // <-- this is what I am talking about
this.foo = _fooModel.foo;
this.bar = _fooModel.bar
}
}
is there a better (more elegant and readable to be specific) way to reproduce this? I'm mainly talking about the if undefined return statement. Which will apply their default values if it returns, of course.