Beim Erstellen eines Datensatzes eines einzelnen Elements vom Typ unit
ist der generierte Klassenkonstruktor ungültig und erzeugt zur Laufzeit einen ReferenceError.
Fable REPL-Beispiele...
type Test = {
Abc: unit
}
printfn "%A" <| { Abc = () }
produziert:
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());
Beachten Sie, dass dem Konstruktor das abc
Argument fehlt, das zum Initialisieren des Felds verwendet wird.
type Test = {
Abc: unit
Xyz: int
}
printfn "%A" <| { Abc = (); Xyz = 123 }
produziert:
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));
Wenn also dem Datensatz ein weiteres Feld hinzugefügt wird, wird der Konstruktor richtig gebildet.
Spätestens alles (Fable 1), wie auch über die REPL beobachtet.
Vielen Dank, dass Sie @xdaDaveShaw überprüft haben! Wäre es in Ordnung, dieses Problem zu schließen, wenn es mit Fable 2 @SirUppyPancakes für Sie funktioniert?
Ja, definitiv!
Hilfreichster Kommentar
Sieht gut aus in Fable2
Hier ist eine Nachbildung davon, die funktioniert .
Konsole:
{Abc = null}