I'm trying construct the class's object from the array.
import searchData from '../somepath/data.json';
And the data.json file have the following data.
[
{
"name": "London"
},
{
"name": "Paris",
}
]
Then I'm looping it using the forEach.
searchData.forEach((obj: OneClass) => {
});
Here is the class
export class OneClass{
readonly name: string;
}
It is not working well, I'm getting some kind of type error.
But when I just change the type of searchData to any then it works perfectly,
const searchData: any = [
{
'name': 'a'
},
{
'name': 'b'
},
];
Note: some code are missing due to privacy restriction, so just trying to understand how the construct the object of typescript class using array objects.
Edited:
The json data was importing using the following method.
import searchData from '../somepath/data.json';
interface, not aclass, if you don't have any methods and no prototype inheritance but only plain data.