I'm attempting to define a class in TypeScript, but I keep encountering the error shown below.
Here is the execution log where the error occurs:
[LOG]: "adding"
[LOG]: undefined
[ERR]: Cannot set property 'hello' of undefined
class CustomDataStructure {
private _data: any;
public CustomDataStructure() {
this._data = {};
}
public addItem(value: string) {
console.log("adding");
console.log(this._data)
this._data[value] = new Date().getTime();
}
public removeItem(key: string) {
delete this._data[key];
}
public showData() {
return this._data;
}
}
let ss = new CustomDataStructure();
ss.addItem("hello");