Repository navigation
feat: enhance typing with interfaces and lesser coupling #700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright (c) 2026. | ||
| * Author Peter Placzek (tada5hi) | ||
| * For the full copyright and license information, | ||
| * view the LICENSE file that was distributed with this source code. | ||
| */ | ||
|
|
||
| import type { ICondition } from '../condition'; | ||
| import type { IFilters } from './types'; | ||
|
|
||
| export function isFilters( | ||
| input: ICondition, | ||
| operator?: string, | ||
| ) : input is IFilters { | ||
| if (!Array.isArray(input)) return false; | ||
|
|
||
| if (operator) { | ||
| return operator === input.operator; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,24 @@ | |
| * view the LICENSE file that was distributed with this source code. | ||
| */ | ||
|
|
||
| import type { Filters } from './module'; | ||
| import type { ICondition } from '../condition'; | ||
|
|
||
| export interface IFiltersVisitor<R> { | ||
| visitFilters(expr: Filters): R; | ||
| visitFilters(expr: IFilters): R; | ||
| } | ||
|
Comment on lines
10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find and examine the clear() method in module.ts
find . -name "module.ts" -path "*/parameter/filters/collection/*" | head -5Repository: tada5hi/rapiq Length of output: 115 🏁 Script executed: #!/bin/bash
# Search for the clear() method in the filters collection directory
rg "clear\s*\(" packages/core/src/parameter/filters/collection/ -A 5 -B 2Repository: tada5hi/rapiq Length of output: 1076 The The loop condition Buggy codeclear() {
for (let i = this.value.length - 1; i === 0; i--) {
this.value.splice(i, 1);
}
}Change the condition to 🤖 Prompt for AI Agents |
||
|
|
||
| export interface IFilters< | ||
| T extends ICondition = ICondition, | ||
| > { | ||
| readonly operator: string; | ||
|
|
||
| readonly value : T[]; | ||
|
|
||
| accept<R>(visitor: IFiltersVisitor<R>) : R; | ||
|
|
||
| add(child: T) : void; | ||
|
|
||
| clear() : void; | ||
|
|
||
| flatten(items?: T[]) : IFilters<T>; | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical bug:
Array.isArray(input)always returnsfalseforICondition/IFiltersobjects.The
IConditionandIFiltersinterfaces are objects withoperatorandvalueproperties—they are not arrays themselves. The checkArray.isArray(input)will always fail, making this type guard non-functional.To distinguish
IFiltersfrom a plainIConditionorIFilter, consider checking for the presence ofIFilters-specific properties (like whethervalueis an array) or methods.🐛 Proposed fix
export function isFilters( input: ICondition, operator?: string, ) : input is IFilters { - if (!Array.isArray(input)) return false; + if (!Array.isArray(input.value)) return false; if (operator) { return operator === input.operator; } return true; }Note: This fix assumes
IFiltersis the only condition type with an arrayvalue. IfIFilteror other condition types can also have array values, additional discrimination logic may be needed (e.g., checking for'accept' in inputor a dedicated type discriminator property).🤖 Prompt for AI Agents