I have the following signal store feature that uses Entity, and I'm getting an error when adding an entity. I need support with resolving it:
This is the signal store feature:
const recordConfig = entityConfig({
collection: 'records',
entity: type<Record>,
selectId: (record) => record().pid,
});
export function withRecord() {
return signalStoreFeature(
withEntities(recordConfig),
withMethods((store, campaignAPI = inject(CampaignAPI)) => ({
appendRecord(
campaignPID: number,
ctpid: number,
recordData: RecordGetResponseModel
): Record {
const record: Record = {
pid: ctpid,
campaignPID: campaignPID,
data: recordData,
};
patchState(store, addEntity(record, recordConfig));
return record;
},
}))
);
}
I found the issue, from the whole time I defined entity type wrong, missed to add parenthesis at the end.
const recordConfig = entityConfig({
collection: 'records',
entity: type<Record>(),
selectId: (record) => record().pid,
});