ts-optchain icon indicating copy to clipboard operation
ts-optchain copied to clipboard

function not bind to owner

Open fatfatson opened this issue 6 years ago • 1 comments

now the binding has to be done manually:

oc(res).value.getNo().bind(oc(res.value))()

could this be done auto?

fatfatson avatar Sep 08 '19 23:09 fatfatson

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");
  });

fatfatson avatar Sep 09 '19 08:09 fatfatson