In my Node.js project using TypeScript, I have defined the Tariff and Tariffs classes. I also generated fake data in JSON format that should align with these Classes. However, I encountered an error in the resolve()
method stating:
Argument of type '{ blabbla... ' is not assignable to parameter of type 'Tariffs | PromiseLike'.
export class FakeDataProvider implements IDataProvider {
loadTariffs?(request: LoadTariffsRequest): Promise<Tariffs> {
return new Promise<Tariffs>((resolve, reject) => {
resolve(fakeTariffs);
});
}
}
Additionally, I have separate files where I define and export the classes as follows:
export class Tariff {
tariffOptionId: number = 0;
name: string = '';
}
export class Tariffs {
// tariff: Tariff = new Tariff(); // this does not work
tariff: Array<Tariff> = []; // this does not work too
}
Furthermore, I exported mock-up JSON data in a different file:
let fakeTariffs =
{
'tariffs': {
'tariff': [
{ "name": "tariff1", "tariffOptionId": 1 },
{ "name": "tariff2", "tariffOptionId": 2 },
{ "name": "tariff3", "tariffOptionId": 3 }
]
}
};
export default fakeTariffs;
I am seeking guidance on how to rectify the compatibility issue between my classes and the fake data. What modifications can be made for them to align properly?