Skip to content
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

anyOf is wrongly creating a union with the array of T #31

Open
alykamb opened this issue Mar 19, 2024 · 0 comments
Open

anyOf is wrongly creating a union with the array of T #31

alykamb opened this issue Mar 19, 2024 · 0 comments

Comments

@alykamb
Copy link

alykamb commented Mar 19, 2024

When we have a union of multiple objects, all of them have a type property, we cannot check the type property because of the union with an array. And the value itself will never be an array, it just needs to be checked with each possible value:

example:

  export type RangeFilter = {
    type: "filter_range";
    id: string;
    displayName: string;
    min: number;
    max: number;
    step?: number | undefined;
    minSelected?: number | undefined;
    maxSelected?: number | undefined;
  };
  export type SelectFilterValue = {
    label: string;
    value: string;
    selected?: boolean | undefined;
    productCount?: number | undefined;
  };
  export type SelectFilter = { id: string; displayName: string; values: Array<SelectFilterValue> };
  export type SingleSelectFilter = { type: "filter_single_select" } & SelectFilter;
  export type MultiSelectFilter = { type: "filter_multi_select" } & SelectFilter;
  
  export type Filters =
    | RangeFilter
    | SingleSelectFilter
    | MultiSelectFilter
    | Array<RangeFilter | SingleSelectFilter | MultiSelectFilter>; // wrong, it will never be an array, it can only be one of the objects, or something that matches multiple objects at the same time.

Although the generation part might be complicated and blow up too fast, maybe I'm going over the top, but I think the correct type needs to address every possible combination:

 export type Filters =
    | RangeFilter
    | SingleSelectFilter
    | MultiSelectFilter
    | (RangeFilter & SingleSelectFilter)
    | (SingleSelectFilter & MultiSelectFilter)
    | (RangeFilter & MultiSelectFilter)
    | (RangeFilter & SingleSelectFilter & MultiSelectFilter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant