Lors de la création d'un enregistrement d'un seul élément de type unit
, le constructeur de classe généré n'est pas valide et produit une ReferenceError au moment de l'exécution.
Échantillons Fable REPL...
type Test = {
Abc: unit
}
printfn "%A" <| { Abc = () }
produit :
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());
Notez qu'il manque au constructeur l'argument abc
qu'il utilise pour initialiser le champ.
type Test = {
Abc: unit
Xyz: int
}
printfn "%A" <| { Abc = (); Xyz = 123 }
produit :
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));
Ainsi, lorsqu'un autre champ est ajouté à l'enregistrement, le constructeur est correctement formé.
Dernier tout (Fable 1), comme observé via le REPL également.
Merci d'avoir vérifié @xdaDaveShaw ! Serait-il acceptable de fermer ce problème si cela fonctionne pour vous avec Fable 2 @SirUppyPancakes ?
Oui, certainement !
Commentaire le plus utile
Ça a l'air bien dans Fable2
Voici une réplique de celui-ci qui fonctionne .
Console :
{Abc = null}