I am attempting to convert a JSON source array with all string values into another array of typed objects, but I keep encountering errors. How can I correct this code properly? Thank you.
Error 1: There is an issue with converting type '({ Id: string; CompanyName: string; ...)[]' to type 'Dest'. The two types do not have sufficient overlap, which may result in an error. If this conversion was intentional, consider first converting the expression to 'unknown'.
Error 2: In '../grid-second.component.ts:12', there is a TypeScript error (TS2740) indicating that the type 'Dest' is missing essential properties present in type 'any[]': length, pop, push, concat, and more. 12 public gridData: any[] = destination;
export const source = [{
'Id': 'ALFKI',
'CompanyName': 'Alfreds Futterkiste',
'DOB': '01/31/2000' // optional field
}, {
'Id': 'ANATR',
'CompanyName': 'Ana Bokov Emparedados y helados',
},
export class Dest{
public Id: string = "";
public CompanyName: string = "";
public DOB?: Date
}
export const destination = <Dest>source; // Error 1.
Within the Angular component:
public gridData: any[] = destination; // Error 2.