T
TanStack2y ago
genetic-orange

Reusable cell renderer without 'any' type

Hello, I was unable to find any post or issue on this, but probably I was searching for the wrong keywords, as I can't believe, that anyone else had this problem :D I have a function for rendering dates into a readable format in cells, like this:
export const DateCell = (info: CellContext<any, string>) =>
DateTime.fromISO(info.getValue()).toLocaleString(defaultDateFormat);
export const DateCell = (info: CellContext<any, string>) =>
DateTime.fromISO(info.getValue()).toLocaleString(defaultDateFormat);
Now I want to get rid of the any, as I am trying to avoid any types whereever possible. Using unknown or never both leads to problems when using this in a column definition. Something like this shows up:
Types of parameters 'defaultOptions' and 'defaultOptions' are incompatible.
Type 'TableOptions<unknown>' is not assignable to type 'TableOptions<WebhookResponse>'.
Types of property 'data' are incompatible.
Type 'unknown[]' is not assignable to type 'WebhookResponse[]'.
Type 'unknown' is not assignable to type 'WebhookResponse'.ts(2322)
Types of parameters 'defaultOptions' and 'defaultOptions' are incompatible.
Type 'TableOptions<unknown>' is not assignable to type 'TableOptions<WebhookResponse>'.
Types of property 'data' are incompatible.
Type 'unknown[]' is not assignable to type 'WebhookResponse[]'.
Type 'unknown' is not assignable to type 'WebhookResponse'.ts(2322)
Is there any way to solve this? Or do I have to explicitly use any here?
4 Replies
harsh-harlequin
harsh-harlequin2y ago
The any should represent the data type for the whole table
genetic-orange
genetic-orangeOP2y ago
Is there no way to avoid the any type? In my examle it is irrelevant for the function, which type the data rows have, as only the value is used
harsh-harlequin
harsh-harlequin2y ago
It looks like the data type for your table is WebhookResponse so you can just use that
genetic-orange
genetic-orangeOP2y ago
In this case yes, but I wanted to have a CellComponent that I can just use in any table. Sorry for the late reply :)

Did you find this page helpful?