I'm facing challenges in defining an interface or type for my dataset, and encountering some errors. Here is the incorrect interfaces and code that I'm using:
interface IVehicle {
[key: number]: { model: string, year: number };
}
interface IVehicles {
[type: string]: Array<IVehicle>
}
const DATASET: IVehicles = {
CAR: [
["BMW", {
model: "520d",
year: 2015,
}],
["Audi", {
model: "A4",
year: 2011,
}]
],
MOTORCYCLE: [
["YAMAHA", {
model: "R6",
year: 2020,
}],
["DUCATI", {
model: "Monster",
year: 2018,
}]
]
}
console.log(DATASET);
An error received from TypeScript:
Type 'string' is not assignable to type '{ model: string; year: number; }'.
Access TypeScript Playground with this code: Playground Link