Imagine having an interface called TableHeader
:
interface TableHeader{
key: string,
value: string,
}
Next, we need to create an interface for TableData
, where:
interface TableData{
// ????
}
In this table data, the key
should be of the type that matches one of the keys in TableHeader[]
,
for instance if we define
const tableHeaders : tableHeader[]=[
{ key: 'index', value: 'Index'},
{ key: 'firstName', value: 'First Name'},
{ key: 'lastName', value: 'Last Name'}
]
then, when we declare
const tableData: TableData[] = [
{
// each object in this array must include keys `index`, `firstName`, `lastName`
// along with their respective values (e.g. strings).
},
{
.
.
.
},
]
What would be the best way to accomplish this?