I have an object to store cached data which should look like this:
private data = {
'some_thing': new DataModel(),
'another_name': new DataModel()
}
I'm trying to assign an empty object to it in the constructor:
this.data = {}; // produces build error
Basically, i need to define the type of "data" field to say that it's going to have keys with random names and values of type DataModel. I've tried to do this:
private data: Object<DataModel>
But this is invalid. How would i specify a correct type?
It should be:
private data: { [name: string]: DataModel };
And then this should work:
this.data = {};
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments