When creating a record of a single element of type unit, the generated class constructor is invalid and produces a ReferenceError at run-time.
Fable REPL samples...
type Test = {
Abc: unit
}
printfn "%A" <| { Abc = () }
produces:
import { setType } from "fable-core/Symbol";
import _Symbol from "fable-core/Symbol";
import { compareRecords, equalsRecords, Unit } from "fable-core/Util";
import { printf, toConsole } from "fable-core/String";
export class Test {
constructor() {
this.Abc = abc;
}
[_Symbol.reflection]() {
return {
type: "Test.Test",
interfaces: ["FSharpRecord", "System.IEquatable", "System.IComparable"],
properties: {
Abc: Unit
}
};
}
Equals(other) {
return equalsRecords(this, other);
}
CompareTo(other) {
return compareRecords(this, other) | 0;
}
}
setType("Test.Test", Test);
toConsole(printf("%A"))(new Test());
Notice that the constructor is missing the abc argument that it uses to initialize the field.
type Test = {
Abc: unit
Xyz: int
}
printfn "%A" <| { Abc = (); Xyz = 123 }
produces:
import { setType } from "fable-core/Symbol";
import _Symbol from "fable-core/Symbol";
import { compareRecords, equalsRecords, Unit } from "fable-core/Util";
import { printf, toConsole } from "fable-core/String";
export class Test {
constructor(abc, xyz) {
this.Abc = abc;
this.Xyz = xyz | 0;
}
[_Symbol.reflection]() {
return {
type: "Test.Test",
interfaces: ["FSharpRecord", "System.IEquatable", "System.IComparable"],
properties: {
Abc: Unit,
Xyz: "number"
}
};
}
Equals(other) {
return equalsRecords(this, other);
}
CompareTo(other) {
return compareRecords(this, other) | 0;
}
}
setType("Test.Test", Test);
toConsole(printf("%A"))(new Test(null, 123));
So when another field is added to the record, the constructor is properly formed.
Latest everything (Fable 1), as observed via the REPL as well.
Thanks for checking @xdaDaveShaw! Would it be OK to close this issue if it works for you with Fable 2 @SirUppyPancakes?
Yep, definitely!
Most helpful comment
Looks OK in Fable2
Here's a Repl of it working.
Console:
{Abc = null}