Skip to content

Commit

Permalink
fix(core): fix recursive logical operation value type
Browse files Browse the repository at this point in the history
  • Loading branch information
whimzyLive committed Mar 12, 2022
1 parent 71c2b28 commit 8f7ae30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
24 changes: 14 additions & 10 deletions packages/core/src/classes/expression/condition-options-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,25 @@ type AttributeConditionOptions<Entity> =

type RecursiveConditionOptions<Entity> = {
// for `AND` and `OR` logical operators require at least one of defined options or other self
[key in Extract<ConditionType.LogicalOperator, 'OR' | 'AND'>]: Partial<
AttributeConditionOptions<Entity> &
// manually infer recursive type
RecursiveConditionOptions<Entity>
> extends infer R
[key in Extract<ConditionType.LogicalOperator, 'OR' | 'AND'>]:
| Partial<
AttributeConditionOptions<Entity> &
// manually infer recursive type
RecursiveConditionOptions<Entity>
>
| {} extends infer R
? R
: never;
} &
// for `NOT` logical operators require one from defined options or other self
{
[key in Extract<ConditionType.LogicalOperator, 'NOT'>]: Partial<
AttributeConditionOptions<Entity> &
// manually infer recursive type
RecursiveConditionOptions<Entity>
> extends infer R
[key in Extract<ConditionType.LogicalOperator, 'NOT'>]:
| Partial<
AttributeConditionOptions<Entity> &
// manually infer recursive type
RecursiveConditionOptions<Entity>
>
| {} extends infer R
? R
: never;
} &
Expand Down
24 changes: 14 additions & 10 deletions packages/core/src/classes/expression/filter-options-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,25 @@ type AttributeFilterOptions<Entity, PrimaryKey> =

type RecursiveFilterOptions<Entity, PrimaryKey> = {
// for `AND` and `OR` logical operators require at least one of defined options or other self
[key in Extract<FilterType.LogicalOperator, 'OR' | 'AND'>]: Partial<
AttributeFilterOptions<Entity, PrimaryKey> &
// manually infer recursive type
RecursiveFilterOptions<Entity, PrimaryKey>
> extends infer R
[key in Extract<FilterType.LogicalOperator, 'OR' | 'AND'>]:
| Partial<
AttributeFilterOptions<Entity, PrimaryKey> &
// manually infer recursive type
RecursiveFilterOptions<Entity, PrimaryKey>
>
| {} extends infer R
? R
: never;
} &
// for `NOT` logical operators require one from defined options or other self
{
[key in Extract<FilterType.LogicalOperator, 'NOT'>]: Partial<
AttributeFilterOptions<Entity, PrimaryKey> &
// manually infer recursive type
RecursiveFilterOptions<Entity, PrimaryKey>
> extends infer R
[key in Extract<FilterType.LogicalOperator, 'NOT'>]:
| Partial<
AttributeFilterOptions<Entity, PrimaryKey> &
// manually infer recursive type
RecursiveFilterOptions<Entity, PrimaryKey>
>
| {} extends infer R
? R
: never;
} &
Expand Down

0 comments on commit 8f7ae30

Please sign in to comment.