Skip to content

Commit

Permalink
Merge pull request #397 from emilefokkemanavara/fix/rule-types
Browse files Browse the repository at this point in the history
fix: type of Rule constructor and Rule's name
  • Loading branch information
chris-pardy authored Nov 20, 2024
2 parents fee2d42 + e369275 commit e244b18
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions test/rule.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ describe("Rule", () => {
});

describe("constructor()", () => {
it("can be initialized without anything", () => {
const rule = new Rule();
expect(rule.name).toBeUndefined();
})

it("can be initialized with priority, conditions, event, and name", () => {
const condition = {
all: [Object.assign({}, conditionBase)],
Expand Down
5 changes: 5 additions & 0 deletions test/types.test-d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ describe("type tests", () => {
const rule = new Rule(ruleProps);
const ruleFromString: Rule = new Rule(JSON.stringify(ruleProps));

it("name of rule is possibly undefined", () => {
const ruleWithoutInit = new Rule();
expectTypeOf<string | undefined>(ruleWithoutInit.name);
})

it("returns the engine when adding a rule", () => {
expectTypeOf<Engine>(engine.addRule(rule));
});
Expand Down
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export interface RuleResult {
}

export class Rule implements RuleProperties {
constructor(ruleProps: RuleProperties | string);
name: string;
constructor(ruleProps?: RuleProperties | string);
name?: string;
conditions: TopLevelCondition;
event: Event;
priority: number;
Expand Down

0 comments on commit e244b18

Please sign in to comment.