Adding custom Roll class to CONFIG.Dice.rolls

Hi guys, Currently re-implementing an abandoned system to be able to use it in Foundry 11+. I have a custom created Roll class that extends Roll<D> as defined in the foundry-vtt-types module. I got the class to actually roll the way I want but no I'm focussing on the Chat Message it should give out. However for the system to be able to recreate the instance of my roll object from the provisioned data I probably need to configure the CONFIG.Dice.rolls to accept my custom class, because if I do not the message holds a rolls variable that holds the following as an array element
0: "{"class":"RollSR6","options":{},"dice":[],"formula":"5d6cs>=5","terms":[{"class":"Die","options":{"flavor":null},"evaluated":true,"number":5,"faces":6,"modifiers":["cs>=5"],"results":[{"result":4,"active":true,"success":false,"count":0},{"result":2,"active":true,"success":false,"count":0},{"result":2,"active":true,"success":false,"count":0},{"result":2,"active":true,"success":false,"count":0},{"result":1,"active":true,"success":false,"count":0}]}],"total":0,"evaluated":true}"
0: "{"class":"RollSR6","options":{},"dice":[],"formula":"5d6cs>=5","terms":[{"class":"Die","options":{"flavor":null},"evaluated":true,"number":5,"faces":6,"modifiers":["cs>=5"],"results":[{"result":4,"active":true,"success":false,"count":0},{"result":2,"active":true,"success":false,"count":0},{"result":2,"active":true,"success":false,"count":0},{"result":2,"active":true,"success":false,"count":0},{"result":1,"active":true,"success":false,"count":0}]}],"total":0,"evaluated":true}"
This in theory is the correct object, however it is stored as a string, presumably because it can't convert/parse it correctly. I tried configuring the CONFIG variable to accept my class in the array given to Dice.rolls
CONFIG.Dice.rolls = [RollSR6];
CONFIG.Dice.rolls = [RollSR6];
This however results in a type issue, basically sying 'undefined' is not assignable to RealRoll. This is the type I'm using to type my custom class.
class class RollSR6 extends Roll<RealRoll> {
...
}
class class RollSR6 extends Roll<RealRoll> {
...
}
1 Reply
Max
MaxOP4w ago
I'm also passing a constructor to call the super function with my type
constructor(formula: string, data: RealRoll, options?: RollSR6["options"]) {
super(formula, data, options);
this.rollData = data;

console.log(`Shadowrun6 | Executing roll=[${formula}]`);

if (formula.indexOf("@initiative") > -1) {
console.debug("Shadowrun 6 | Initiative Roll detected");
this.rollData.rollType = RollType.Initiative;
}
}
constructor(formula: string, data: RealRoll, options?: RollSR6["options"]) {
super(formula, data, options);
this.rollData = data;

console.log(`Shadowrun6 | Executing roll=[${formula}]`);

if (formula.indexOf("@initiative") > -1) {
console.debug("Shadowrun 6 | Initiative Roll detected");
this.rollData.rollType = RollType.Initiative;
}
}
The actual error I get is
Type 'typeof RollSR6' is not assignable to type 'typeof Roll'.
Types of construct signatures are incompatible.
Type 'new (formula: string, data: RealRoll, options?: InexactPartial<Options> | undefined) => RollSR6' is not assignable to type 'new <D extends AnyObject = AnyObject>(formula: string, data?: D | undefined, options?: InexactPartial<Options> | undefined) => Roll<D>'.
Types of parameters 'data' and 'data' are incompatible.
Type 'D | undefined' is not assignable to type 'RealRoll'.
Type 'undefined' is not assignable to type 'RealRoll'.ts(2322)
Type 'typeof RollSR6' is not assignable to type 'typeof Roll'.
Types of construct signatures are incompatible.
Type 'new (formula: string, data: RealRoll, options?: InexactPartial<Options> | undefined) => RollSR6' is not assignable to type 'new <D extends AnyObject = AnyObject>(formula: string, data?: D | undefined, options?: InexactPartial<Options> | undefined) => Roll<D>'.
Types of parameters 'data' and 'data' are incompatible.
Type 'D | undefined' is not assignable to type 'RealRoll'.
Type 'undefined' is not assignable to type 'RealRoll'.ts(2322)
Maybe some of you instantly see my issue and can be help with this problem. Any help that leads me into the right direction is greatly appreciated.
Want results from more Discord servers?
Add your server