Skip to content

Commit eb52b37

Browse files
fix: Replace raw in operator check with type guard for PropertyFilterTokenGroup discrimination (cloudscape-design#131)
Co-authored-by: Nathnael_D <109980176+NathanZlion@users.noreply.github.com>
1 parent dad864d commit eb52b37

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/operations/property-filter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,15 @@ function filterByToken<T>(token: PropertyFilterToken, item: T, filteringProperti
173173
return freeTextFilter(token.value, item, token.operator, filteringPropertiesMap);
174174
}
175175

176+
function isPropertyFilterTokenGroup(t: PropertyFilterToken | PropertyFilterTokenGroup): t is PropertyFilterTokenGroup {
177+
const key: keyof PropertyFilterTokenGroup = 'operation';
178+
return key in t;
179+
}
180+
176181
function defaultFilteringFunction<T>(filteringPropertiesMap: FilteringPropertiesMap<T>) {
177182
return (item: T, query: PropertyFilterQuery) => {
178183
function evaluate(tokenOrGroup: PropertyFilterToken | PropertyFilterTokenGroup): boolean {
179-
if ('operation' in tokenOrGroup) {
184+
if (isPropertyFilterTokenGroup(tokenOrGroup)) {
180185
let result = tokenOrGroup.operation === 'and' ? true : !tokenOrGroup.tokens.length;
181186
for (const group of tokenOrGroup.tokens) {
182187
result = tokenOrGroup.operation === 'and' ? result && evaluate(group) : result || evaluate(group);

0 commit comments

Comments
 (0)