Rank 3: Container
addMessage() { const data = { message: '!!! 2nd message !!!', sender: this.currentUserId, }; const promise = this.chat3Service.getRoom(this.roomId).then(room => { room.messages.push(data); return this.chat3Service.updateRoom(this.roomId, room); }); promise.then( function (response) { console.log(response); // Success }, function (error) { console.log(error); // Failure } ); }Copilot suggesting me to get all data first then push and update the relation again.
Is there any better way to do that ? I was trying to do
addMessage() { const data = { message: '!!! 2nd message !!!', sender: this.currentUserId, }; const promise = this.chat3Service.updateRoom(this.roomId, { messages: [...data], // error warning this line }); promise.then( function (response) { console.log(response); // Success }, function (error) { console.log(error); // Failure } ); }but i am getting following error
Type '{ message: string; sender: string; }' must have a '[Symbol.iterator]()' method that returns an iterator.ts(2488)