T
TanStack3y ago
correct-apricot

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
other-emerald
other-emerald3y ago
The any should represent the data type for the whole table
correct-apricot
correct-apricotOP3y 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
other-emerald
other-emerald3y ago
It looks like the data type for your table is WebhookResponse so you can just use that
correct-apricot
correct-apricotOP3y 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?