gabrielguerrero / ngrx-traits

NGRX Traits is a library to help you compose and reuse state logic in your angular app. There is two versions, @ngrx-traits/signals supports ngrx-signals, and @ngrx-traits/{core, common} supports ngrx.
MIT License
44 stars 3 forks source link

withCalls typedCallConfig that has a resultProp doesnt generate the correct type with the prop #70

Closed gabrielguerrero closed 1 month ago

gabrielguerrero commented 1 month ago

The following code should generate a property called baz but it doesnt

const Store = signalStore(
          withState({ foo: 'bar' }),
          withCalls((store) => ({
            testCall: typedCallConfig({
              call: ({ ok }: { ok: boolean }) => {
                return ok
                  ? apiResponse
                  : apiResponse.pipe(
                      tap(() => throwError(() => new Error('fail'))),
                    );
              },
              resultProp: 'baz', // <--  store result in baz property 
              onSuccess: (result) => {
                // patchState should be able to update the store inside onSuccess
                patchState(store, { foo: result });
              },
              onError,
            }),
          })),
        );

As a workaround you can omit using typedCallConfig and use an object for the config but that loses the type for the result on the onSuccess method