I am receiving this build error:
Type '{ executionTime: number; schema: { \[k: string\]: { name: string; index: number; type: string; }; }; values: Document\[\]\[\]; }' is not assignable to type 'DataGridData'.
Types of property 'schema' are incompatible.
Type '{ \[k: string\]: { name: string; index: number; type: string; }; }' is not assignable to type 'Schema'.
'string' index signatures are incompatible.
Type '{ name: string; index: number; type: string; }' is not assignable to type '{ name: string; index: number; type: SchemaDataType; }'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type 'SchemaDataType'.
It boils down to type 'string' not being compatible with explicitly defined type SchemaDataType. Here is that defined type:
export type SchemaDataType =
| 'DateTime'
| 'Decimal'
| 'Guid'
| 'Int32'
| 'String';
'string' is not being recognized as 'String'.
function mapKeys() {
const docKeys = Object.keys(items);
const result = Object.fromEntries(
docKeys.map((el, index) => {
return [el, { name: el, index, type: el.constructor.name }];
}),
);
return result;
}
This function I created transforms the json response in the DB to a palitable structure for a custom DataGrid that I am trying to implement. I attemted a fix by capitalizing the first letter of 'type' like so but this did not fix the issue:
function mapKeys() {
const docKeys = Object.keys(items);
const result = Object.fromEntries(
docKeys.map((el, index) => {
return [
el,
{
name: el,
index,
type:
el.constructor.name.charAt(0).toUpperCase() +
el.constructor.name.slice(1),
},
];
}),
);
return result;
}