Skip to content

Commit

Permalink
docs(core): Add generics
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbrg committed Jan 28, 2024
1 parent 5df043a commit 26c143a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/services/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ export class Evaluator {
* @param rule The rule to evaluate.
* @param criteria The criteria to evaluate the rule against.
*/
evaluate<T>(rule: Rule, criteria: object | object[]): boolean | any {
evaluate<T>(rule: Rule, criteria: object | object[]): T | boolean {
// Cater for the case where the conditions property is not an array.
const conditions =
rule.conditions instanceof Array ? rule.conditions : [rule.conditions];

if (criteria instanceof Array) {
const result = [];
const result: T | boolean[] = [];
for (const c of criteria) {
result.push(this.evaluateRule<T>(conditions, c, rule?.default));
result.push(this.evaluateRule(conditions, c, rule?.default));
}

return result;
return result as T | boolean;
}

return this.evaluateRule<T>(conditions, criteria, rule?.default);
Expand Down

0 comments on commit 26c143a

Please sign in to comment.