Primeng: Strong Types for Turbo Table

Created on 29 Aug 2018  路  1Comment  路  Source: primefaces/primeng

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

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

Current behavior
A lot of the API for TurboTable uses "any" as the type for arguments, return values, and even column definitions. Not all properties/methods are documented, and those that are could potentially become out of date. Options could also change when updating to a newer version, and currently there would be no compile-time checking around this.

Expected behavior
Ideally, everything would have interfaces or other strong types, and "any" would be rarely aside from the row data itself, which should allow for anything.
Here are some specific cases I've encountered that have forced me to dig into source code, along with some low-hanging fruit encountered while looking through the source:

  • Table.columns input property
    ** An interface that specified properties like header, field, exportable would be very helpful
  • Table.filter method
    ** Parameter matchMode has to be one of specific subset of strings. Specifically, it has to be a key of the Table,filterConstraints lookup, but there's no way to know what those are without looking at the source code. If filterConstraints had an interface, you could type it as matchMode: keyof FilterConstraints, or at least create a type MatchMode = 'startsWith' | 'endsWith' | 'equals' | ...
  • Table.contextMenu
    ** Presumable this has to be an instance of p-context-menu, but if you don't want to limit it to that, it definitely needs be something that implements a show() function. Either should be typed as ContextMenu or some IContextMenu { show(event: Event): void; }
  • LazyLoadMetadata (Table.onLazyLoad)
    ** Typing this event emitter would be provide intellisense when you go to handle the event. The createLazyLoadMetadata function create a very specific contract.
  • Table.exportCSV(options?: any)
    ** I think currently the only option is selectionOnly, but it would be nice to make that explicit. And if you add additional options in the future, they'll become immediately apparent.
  • Table.columnResizeMode is typed as string, but changing it to be 'fit' | 'expand' (or an enum) would better validate input and provide intellisense.
  • Other event emitters that would benefit:
    ** onPage, sortFunction, onSort, selectionChanged (Array), onRowSelect, onRowUnselect, onContextMenuSelect, onHeaderCheckboxToggle, onFilter, onRowCollapse, onRowExpand, onColResize, onColReorder, onRowReorder, onEditInit, onEditComplete

What is the motivation / use case for changing the behavior?
Better IntelliSense while developing. Compile time error reporting for many possible mistakes. Assurance when you upgrade to a new version whether contracts have changed. Potentially less defects created when changing the code.

PrimeNG version: 6.1.2

Language: TypeScript

enhancement

Most helpful comment

Can we get some update on this? There was a PR related to this but it has been rejected with the Promise of doing it "in-house", and that was over a year ago.

>All comments

Can we get some update on this? There was a PR related to this but it has been rejected with the Promise of doing it "in-house", and that was over a year ago.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KannanMuruganmony picture KannanMuruganmony  路  3Comments

pchristou picture pchristou  路  3Comments

papiroca-tm picture papiroca-tm  路  3Comments

jisqaqov picture jisqaqov  路  3Comments

jisqaqov picture jisqaqov  路  3Comments