Использование Reason gentype с классами Typescript - PullRequest
0 голосов
/ 26 марта 2020

В этом примере привязка из репозитория gentype:

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

Спасибо.

...