I'm struggling with defining variables in TypeScript. Here's an example code snippet:
interface ItemType {
name: string;
val: string;
id: number;
}
const items: ItemType[] | ItemType[][] = [
{ name: 'russia', val: 'ru', id: 1 },
{ name: 'england', val: 'en', id: 2 },
{ name: 'america', val: 'us', id: 3 },
{ name: 'canada', val: 'ca', id: 4 },
{ name: 'ukraine', val: 'uc', id: 5 },
[
{ name: 'havana', val: 'hv', id: 6 },
{ name: 'argentina', val: 'ar', id: 7 },
{ name: 'kazahstan', val: 'kz', id: 8 },
]
];
I'm aware that items can be either an array of ItemType or a nested array of ItemType, but I am unsure of the correct way to declare a variable like this. Can generic types help me achieve this? This code seems incorrect :( Any guidance on this would be greatly appreciated.
Thank you.