1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

a little type safety for SignalStore patchState()

Discussão em 'Angular' iniciado por EasterBunnyBugSmasher, Setembro 14, 2025.

  1. I'm still new to signals. And some of my code looks like this:

    withMethods((store, loader = inject(StatusLoader)) => ({
    async load() {
    patchState(store, {loading: true, errorMessage: ''});
    try {
    const sheetStatus = await loader.load(match.id);
    patchState(store, {status: sheetStatus, loading: false, errorMessage: ''});
    } catch (err: any) {
    patchState(store, {loading: false, errorMessage: err?.message ?? 'Fehler'});
    }
    }
    }));


    and I wish I had a little type safety for the patchState() function. One thing is mistyping while coding (minor issue). But I often also miss it when trying to understand code. So many times where I ask myself (or rather ask my IDE): "where is 'loading' changed?". That's rather trivial in this example. But when dealing with larger models, I often search for the spots in the code where certain attributes are changed. And in cases where lots of entities have an attribute like "state", the search can be pretty difficult.

    So is there any good practices to support that? Or is it something I just have to live with in the typescript world?

    Continue reading...

Compartilhe esta Página