在此示例中,来自基因型回购的绑定:
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
设置了一个仓库谢谢。