I have an array that should content an explicit object. By some reason typescript doesn't show me errors if I break this object. I use column object to knex query.
type Test = {
id: string;
startDate: string;
percentDebitCard: number,
}
const column = {
id: 'bct.id',
startDate: 'bct.startDate',
percentDebitCard: 'bct.percentDebitCard',
};
const allCashBackByType:any=[{
id: "bla",
startDate: "bla",
endDate: "bla",
someKey:"bla",
someKey1:"bla",
someKey2:"bla",
someKey3:"bla"
}]
const test:Test[]=allCashBackByType.map((item: typeof column):Test => ({
id: item.id,
startDate: item.startDate,
percentDebitCard: item.percentDebitCard as number,
}));
Why is this happening and how can it be fixed?
But if I remove method map that make iterations it shows errors
const test:Test[]=[{
id: '11',
startDate: "22",
extraKey:"33"
}];
But I need map.
You can try this
const test:Test[]=allCashBackByType.map((item: any): Test => ({
id: item.id,
startDate: item.startDate,
extraKey: '2222'
}));