0

When I dispatch an Add-Action my Backend is updated and so is my Frontend (due to optimisticAdd: true). But I still get this Error: enter image description here

I debugged everything and found the place where the error happens: The function mustBeEntity(action){...} is called three times. On the third time const id = this.selectId(data); returns undefined, even though data has an valid id called 'id'. I tried setting the selectId in the EntityMetaData resulting in the same Error. Here is my EntyityMetadata:

const entityMetadata: EntityMetadataMap = {
  User: {
    selectId: (user: User) => user.id,
    entityName: 'User',
    entityDispatcherOptions: {
      optimisticAdd: true,
      optimisticDelete: true,
      optimisticUpdate: true,
      optimisticUpsert: true
    }
  }
};

And here is my User Interface:

export interface User {
  id: number
  firstname: string,
  lastName: string,

}

I also got some Screenshots where you can exactly see, that it returns undefined even tho the id is clearly there: enter image description here

The user got an Id of 5, but then:

enter image description here

Is this a bug or do I misunderstand something?

I already Had a look at this Question: ngrx/data - alternate id `has a missing or invalid entity key (id)`

But the only solution provided there is not the problem in my case!

Janka C.
  • 13
  • 3
  • I found the problem: My server returned the Object user: {firstname:'', lastname: '', id: 5}, when NgRx expected {firstname: '', lastname: '', id: 5} (without the 'user:') – Janka C. Jan 13 '23 at 09:05

0 Answers0