NgRx signalStore with generic methods

Discussão em 'Angular' iniciado por Darion Badlydone, Março 5, 2025.

  1. I'm using Angular 19 with Ngrx. I have multiple store with the same methods to handle the CRUD operations. I would like than withMethods use an interface to set this store generic. I tried to pass an interface after the withMethods function but TS not like it.

    This is an example of the store:

    const config = entityConfig({
    entity: type<MyDto>(),
    collection: 'data',
    });

    export const MyStore = signalStore(
    { providedIn: 'root' },
    withEntities(config),
    withMethods((store, service = inject(MyService)) => ({
    create: rxMethod<{ dto: MyDto }>(
    pipe(
    ...
    ),
    ),
    update: rxMethod<MyDto>(
    pipe(
    ...
    ),
    ),
    delete: rxMethod<string>(
    pipe(
    ...
    ),
    ),
    fetch: rxMethod<string>(
    pipe(
    ...
    ),
    ),
    fetchAll: rxMethod<void>(
    pipe(
    ...
    ),
    ),
    })),
    );


    I would like insert the methods create, update, delete, fetch and fetchAll within an interface an set in the withMethods<MyCrudInterface>.

    Continue reading...

Compartilhe esta Página