Skip to content

Commit cecdb36

Browse files
authored
feat: Make the Filter type more specific. (#915) Thanks to @ylixir
Now the type more accurately represents which Filter objects are valid. This will provide better code completion, documentation and allow the typechecker to better help in writing more robust new code and in more easily refactoring existing code.
1 parent aa5e12c commit cecdb36

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

packages/cubejs-client-core/index.d.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,35 @@ declare module '@cubejs-client/core' {
563563
annotation(): QueryAnnotations;
564564
}
565565

566-
export type Filter = {
566+
export type Filter = BinaryFilter | UnaryFilter;
567+
type BinaryFilter = {
567568
dimension?: string;
568569
member?: string;
569-
operator: string;
570-
values?: string[];
570+
operator: BinaryOperator;
571+
values: string[];
571572
};
573+
type UnaryFilter = {
574+
dimension?: string;
575+
member?: string;
576+
operator: UnaryOperator;
577+
values?: never;
578+
};
579+
type UnaryOperator = 'set' | 'notSet';
580+
type BinaryOperator =
581+
| 'equals'
582+
| 'notEquals'
583+
| 'contains'
584+
| 'notContains'
585+
| 'gt'
586+
| 'gte'
587+
| 'lt'
588+
| 'lte'
589+
| 'inDateRange'
590+
| 'notInDateRange'
591+
| 'beforeDate'
592+
| 'afterDate';
593+
594+
572595

573596
type TimeDimensionGranularity = 'hour' | 'day' | 'week' | 'month' | 'year';
574597

0 commit comments

Comments
 (0)