Hildebrandt Tobias
10/28/2024, 2:58 PMFC
with Props
that have generics.
I already saw this https://kotlinlang.slack.com/archives/C0B8L3U69/p1669835459380739 but I can't wrap my head around it somehow.
Small example (shortened for brevity):
external interface CustomTableProps<T : RowData> : Props {
var table: Table<T>
var columns: Array<ColumnDef<T, String>>
var userSettings: TanStackUserSettingsStates
var handleClick: ((Row<T>) -> Unit)?
}
val CustomTable = FC<CustomTableProps<T>> { props -> // Error here at <T> unresolved.
val intl = useIntl()
val theme = useTheme()
val (page, setPage) = props.userSettings.page
val (rowsPerPage, setRowsPerPage) = props.userSettings.rowsPerPage
val (showFilters, _) = props.userSettings.showFilters
Box {
sx { overflow = Auto.auto }
<More Code here>
}
}
And the use it like this:
CustomTable {
table = preparedTable
columns = preparedColumns
userSettings: tableUserSettings
}
With val
it doesn't work of course since you can only type them by a receiver type, but even as a function I don't understand how I should build it.
With dynamic
it works, but if possible I'd like to have everything typed so I don't need to do casts on the higher order functions results (handleClick()
).turansky
10/28/2024, 6:13 PMCustomTable<CustomTableProps<MyRowData>> {
table = preparedTable
columns = preparedColumns
userSettings = tableUserSettings
}
Hildebrandt Tobias
10/28/2024, 8:22 PMturansky
10/28/2024, 9:56 PMturansky
10/28/2024, 9:57 PMHildebrandt Tobias
10/29/2024, 8:28 AMHildebrandt Tobias
10/29/2024, 10:50 AMNothing
.
Do you happen to have an Idea how to solve that? Then handleClick
is defined as in the first post.turansky
10/29/2024, 10:56 AMval CustomTable: FC<CustomTableProps<*>> = FC<CustomTableProps<Any>> { ... }
?Hildebrandt Tobias
10/29/2024, 11:02 AMturansky
10/29/2024, 11:20 AMHildebrandt Tobias
10/29/2024, 11:27 AMHildebrandt Tobias
10/29/2024, 11:54 AMdynamic
for the callback for now, it already helps a ton that the rest is typed now.turansky
10/29/2024, 12:14 PMdynamic
isn’t recommended 😉turansky
10/29/2024, 12:14 PMHildebrandt Tobias
10/29/2024, 12:22 PM