Our backend provides data in a specific format, with a data
section containing tabular data and a meta
section describing the columns in the table. The metadata includes information about the type of each column.
For Example
{
meta: [
{name: "foo", type: "NUMBER"},
{name: "bar", type: "STRING"},
{name: "baz", type: "TIMESTAMP"},
],
data:[
[1, "a", 12121232],
[2, "b", 12121232],
[3, "c", 12121232],
]
}
Is there a way to establish the relationship between the meta
and data
using TypeScript?
The objective is to successfully typecheck this function, allowing the use of type information from the meta
section instead of checking the content of each table cell:
const fn = (data:Data) => {
if(data.meta[1].type ==='STRING'){
data.data[0][1].concat('-bar')
}
}