Is it feasible to retrieve the type of object property when that object is nested within a table structure? Take a look at this playground.
function table<ROW extends object, K extends Extract<keyof ROW, string>>({
columns,
data,
}: {
columns: Array<{
id: K
Cell: (value: ROW[K]) => any
}>
data: Array<ROW>
}) {
return null
}
table({
columns: [
{
id: "prop1",
Cell: (value) => value
},
{
id: "prop2",
Cell: (value) => value
}
],
data: [
{
prop1: "dsfdgsfg",
prop2: 23434245
},
{
prop1: "jghfjjk",
prop2: 346466
}
]
})
I am aiming to specify the type of value
(string
for prop1
or number
for prop2
instead of string | number
for both keys) within the columns Cell component.