在Typescript类中使用Reason基因型

在此示例中,来自基因型回购的绑定:

module AbsoluteValue = {
  [@genType.import ("./MyMath","AbsoluteValue")]
  type t = {. "getabs": (. unit) => int};


  /* This is untyped */
  [@bs.send] external getProp: t => int = "getProp";


  /* This is also untyped,as we "trust" the type declaration in absoluteVaue */
  let getabs = (x: t) => {
    let getabs = x##getabs;
    getabs(.);
  };
};

绑定到:

export class AbsoluteValue {
  public prop!: number;
  public getProp(): number {
    return this.prop;
  }
  public getabs(): number {
    return this.prop < 0 ? -this.prop : this.prop;
  }
}

您将如何实例化AbsoluteValue.t对象? 在ts中,我可以这样做,就像这样:

let abs = new AbsoluteValue();
console.log("abs: ",abs);
console.log("abs.prop: ",abs.prop);

abs.prop = 1.1;
console.log("abs.prop: ",abs.prop);

console.log("abs.getProp: ",abs.getProp());

// output

abs:  AbsoluteValue {}
abs.prop:  undefined
abs.prop:  1.1
abs.getProp:  1.1

我将如何在原因方面做到这一点?

我已为这个https://github.com/idkjs/gentype-ts-classes

设置了一个仓库

谢谢。

wushuangbaoying 回答:在Typescript类中使用Reason基因型

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2574711.html

大家都在问