Skip to content

RuleResult class missing from type declarations #352

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jeshuamaxey opened this issue Sep 14, 2023 · 1 comment · Fixed by #390
Closed

RuleResult class missing from type declarations #352

jeshuamaxey opened this issue Sep 14, 2023 · 1 comment · Fixed by #390

Comments

@jeshuamaxey
Copy link

jeshuamaxey commented Sep 14, 2023

RuleResult has a toJSON() method (source)

The RuleResult interface declaration does not include this (source). Also, there is no class declaration for RuleResult.

The impact of this issue is felt when handling rule results, in my case decomposing them from an EngineResult. I ran into the same problem outlined in #172 which was "resolved" with the introduction of the toJSON method to RuleResults. This resolution doesn't help if you're using typescript, as the compiler has no knowledge of this method.

Screenshot 2023-09-14 at 09 54 49

To make my code work around this, I've had to create a new RuleResult type in my code and extend it to include the toJSON method, which is a bit yuck.

A good solution would include:

  1. add and export a RuleResult class declaration which includes the toJSON() method
  2. add and export a RuleResultSerializable type declaration (taking inspiration from the type declaration for Rule class declaration)

Thanks

@doblinger-extron
Copy link

Additionally, result and factResult are missing from RuleResult's conditions property.

I believe the ConditionProperties interface is the right place to add them, i.e.

interface ConditionProperties {
  fact: string;
  operator: string;
  value: { fact: string } | any;
  path?: string;
  priority?: number;
  params?: Record<string, any>;
  name?: string;
  // the following properties are missing
  result: boolean;
  factResult?: any
}

In this example, the failures are filtered by the result property and this causes compilation errors in TypeScript

const detail = ruleResult.conditions.all.filter(condition => !condition.result)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants