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

TreeTable and DataTable | Typescript Definition Bug for global Filters #2378

Closed
tft7000 opened this issue Mar 30, 2022 · 1 comment
Closed
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@tft7000
Copy link

tft7000 commented Mar 30, 2022

filters injected into the TreeTable component should be a key-value object following the documentation. The global filter is supposed to use the key global. The code concerning the global filter suggests the same: https://github.com/primefaces/primevue/blob/master/src/components/treetable/TreeTable.vue#L564

However the type definition defines filters as TreeTableFilterMeta:
https://github.com/primefaces/primevue/blob/master/src/components/treetable/TreeTable.vue#L564

That interface defines the keys as [key: string]: TreeTableFilterMetaData | TreeTableOperatorFilterMetaData;. Those values would be objects.

I am not sure about local filtering (except for the discrepancy to the docs), but it is not the correct definition for the global filter.

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primevue/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=110

Current behavior

if I define filters as TreeTableFilterMeta, I cannot set filters["global"] without getting an TS2322 Typescript error.

If I define filters as { global?: string } (because I just need the global filter) I get the TS2322 Typescript error Type '{ global?: string | undefined; }' is not assignable to type 'TreeTableFilterMeta'. (Type 'string' is not assignable to type 'TreeTableFilterMetaData | TreeTableOperatorFilterMetaData'.)

Expected behavior

Either I have a typescript definition that I could use or I use my own.

Please tell us about your environment:

  • primevue 3.12.2
  • vue 3.2.31
  • typescript 4.5.4

Workaround

I used the following workaround for the global filter:

I created the file primevue.d.ts (name should not matter, I put it in src/types/):

import {
  TreeTableFilterMetaData,
  TreeTableOperatorFilterMetaData,
} from "primevue/treetable";

export interface TreeTableFilterMeta {
  global?: string | undefined;
  /**
   * Filter keys
   * @see TreeTableFilterMetaData
   */
  [key: string]: TreeTableFilterMetaData | TreeTableOperatorFilterMetaData;
}

(Note: it only solves the global filter, I did not check the column filters)

@ZiadJ
Copy link

ZiadJ commented Mar 30, 2022

I've been struggling to fix the error message with TS too. I found a way to fix it temporarily and thought I'd share it:
const searchFilters = ref<TreeTableExpandedKeys>({ global: '' })

@tugcekucukoglu tugcekucukoglu added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Mar 31, 2022
@tugcekucukoglu tugcekucukoglu changed the title TreeTable Typescript Definition Bug for global Filters TreeTable and DataTable | Typescript Definition Bug for global Filters Apr 11, 2022
@tugcekucukoglu tugcekucukoglu added this to the 3.12.5 milestone Apr 11, 2022
@tugcekucukoglu tugcekucukoglu self-assigned this Apr 11, 2022
tugcekucukoglu added a commit that referenced this issue Apr 11, 2022
Fixed #2378 - TreeTable and DataTable | Typescript Definition Bug for…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants