Skip to content

Commit 9515b9b

Browse files
authored
fix: Deep error (#25)
1 parent 559bd68 commit 9515b9b

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-expression-eval",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"description": "json serializable rule engine / boolean expression evaluator",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/test/types/deep.test-d.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {ResolvedConsequence, Rule} from '../../index';
2+
import {expectType} from 'tsd';
3+
4+
type ExpressionFunction1 = {
5+
user: (user: string, context: { userId: string }) => boolean;
6+
}
7+
8+
type ExpressionFunction2 = {
9+
user: (user: string, context: { userId: string }) => boolean;
10+
}
11+
12+
type Context1 = {
13+
timesCounter?: number;
14+
userId: string,
15+
nested: {
16+
value2: number | undefined,
17+
value: number | null,
18+
},
19+
}
20+
21+
type Context2 = {
22+
timesCounter?: number;
23+
userId: string,
24+
nested: {
25+
value2: number | undefined,
26+
value: number | null,
27+
},
28+
}
29+
30+
type ConsequencePayload1 = {
31+
a: number;
32+
}
33+
34+
type ConsequencePayload2 = {
35+
a: number;
36+
}
37+
38+
type RuleFunctionsTable1 = {
39+
rule1: () => void | ResolvedConsequence<ConsequencePayload1>
40+
}
41+
42+
type RuleFunctionsTable2 = {
43+
rule1: () => void | ResolvedConsequence<ConsequencePayload2>
44+
}
45+
46+
type Rule1 = Rule<ConsequencePayload1, RuleFunctionsTable1, Context1, ExpressionFunction1, Date>;
47+
type Rule2 = Rule<ConsequencePayload2, RuleFunctionsTable2, Context2, ExpressionFunction2, Date>;
48+
49+
declare const rule1: Rule1;
50+
declare const rule2: Rule2;
51+
declare const fn: (rule: Rule1) => boolean;
52+
53+
expectType<boolean>(fn(rule1));
54+
expectType<boolean>(fn(rule2));

src/test/types/evaluator.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ expectError(new ExpressionHandler<Context, ExpressionFunction>({userId: 5}, func
5555
expectType<TestExpressionEval>(new ExpressionHandler<Context, ExpressionFunction>({userId: 'sdf'}, functions));
5656
expectError(new ExpressionHandler<Context, ExpressionFunction>({nested: {value: 5}}, functions));
5757
expectError(new ExpressionHandler<Context, ExpressionFunction>({'nested.value': 'sdf'}, functions));
58+
expectError(new ExpressionHandler<Context, ExpressionFunction>({'nested.valu2e': 'sdf'}, functions));
5859
expectType<TestExpressionEval>(new ExpressionHandler<Context, ExpressionFunction>({'nested.value': 5}, functions));
5960
expectError(new ExpressionHandler<Context, ExpressionFunction>({timesCounter: {neq: 'sdf'}}, functions));
6061
expectError(new ExpressionHandler<Context, ExpressionFunction>(

src/types/evaluator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {NonNullable} from './required';
55
export type FuncCompareOp<C extends Context, F extends FunctionsTable<C>, K extends keyof F> =
66
Awaited<Parameters<F[K]>[0]>;
77

8-
export type StringPaths<O extends object, Ignore> =
9-
String.Join<Paths<O, [], Ignore | any[], string>, '.'>;
8+
export type StringPaths<O extends object, Ignore> = any extends O ?
9+
never : (any extends Ignore ? never : String.Join<Paths<O, [], Ignore | any[], string>, '.'>);
1010

1111
export type Primitive = string | number | boolean;
1212

0 commit comments

Comments
 (0)