ts-optchain
ts-optchain copied to clipboard
function not bind to owner
now the binding has to be done manually:
oc(res).value.getNo().bind(oc(res.value))()
could this be done auto?
it("optional chaining equivalence for member function", () => {
interface IX {
s: string;
}
class Y {
constructor(public x?: X) {}
f() {
return this.x && this.x.s;
}
}
class X implements IX {
s = "abc";
y?: Y;
}
var x1 = new X();
var x2 = new X();
x2.y = new Y(x2);
expect(oc(x1).y.f(() => "123")()).toEqual("123");
expect(oc(x2).y.f(() => "123")()).toEqual("abc");
});