Can someone please explain why you can't do this in Typescript?
this.obj.id = 1;
this.obj.str = 'This is string';
But you can do this:
this.obj = { id: 1, str: 'This is string'};
It's not a matter of you can't do but, you're doing it wrong. See Stackblitz Demo
I was able to define by using it like this:
obj = [];
obj2 = { id: 0, str: '' };
this.obj = { id: 1, str: 'This is string' };
this.obj2.id = 1;
this.obj2.str = 'This is string';
console.log(this.obj)
console.log(this.obj2)
this.objinitially? If you didn't define it, you're trying to define properties on something that doesn't exist.undefined.