Reputation: 35
I am having an issue when i tr to initilise an object based on Typescript interface, i am assignining a value but i still get error that the property is underfined.
interface ITableData {
domainObjectName: string;
domainObjectType: string;
recordId: string;
}
interface IDataMap {
recordId?: string;
controlId?: string;
}
interface IMap {
[key: string]: IDataMap;
}
tableData: ITableData[];
dataMap: IMap;
createDataMap() {
Object.keys(this.tableData).forEach(i => {
const recordId = this.tableData[i].recordId;
this.dataMap[recordId] = {
recordId: recordId,
controlId: ''
};
});
}
Based on the research and debugging I did it seems that typescript is complaining by the fact that I am creating an object key without assigning a value but I am assigning a value.
I appreciate any help.
Upvotes: 3
Views: 390
Reputation: 222582
I guess the problem lies right here, this.dataMap[recordId]
you are trying to access particular id from an undefined dataMap. You need to have data within it. Either assign to empty array or fill it with Id which holds the id that you want to access.
Upvotes: 2