Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store params for functions inside withSyncToWebStorage, withStateLogger, and withSyncToRouteQueryParams not correctly inferred #145

Closed
gabrielguerrero opened this issue Oct 1, 2024 · 1 comment · Fixed by #146
Labels

Comments

@gabrielguerrero
Copy link
Owner

The following example get errors in the function because it can not resolve store types

const entity = type<Product>();
export const ProductsLocalStore = signalStore(
  withEntities({ entity }),
  withSyncToWebStorage({
    key: 'sdsd',
    type: 'local',
    filterState: ({ entities }) => ({ entities }), //ERROR entities can not be resolved
  }),
  withStateLogger({
    name: 'sdsd',
    filterState: ({ entities }) => ({ entities }), //ERROR entities can not be resolved
  }),
  withState({
    test: 'test',
    foo: 'foo',
    bar: false,
  }),
  withSyncToRouteQueryParams({
    mappers: [
      {
        queryParamsToState: (query, store) => {
          patchState(store, {
            test: query.test,
            foo: query.foo,
            bar: query.bar === 'true',
          });
        },
        stateToQueryParams: (store) =>
          computed(() => ({
            test: store.test(), //ERROR test, foo and bar can not be resolved
            foo: store.foo(),
            bar: store.bar().toString(),
          })),
      },
    ],
  }),
);

This was not caught by test because it seems to be a bug in how the functions are compiled when return type of the triat is not especified for example:
Screenshot 2024-10-01 at 21 04 29

In the left is how is now and causes the error, on the right is the fix, which is been explicit with the return types.
This also fixes using the library with skibLibCheck: false #91

gabrielguerrero pushed a commit that referenced this issue Oct 1, 2024
Made the return type explicit for withSyncToWebStorage, withStateLogger and
withSyncToRouteQueryParams, before the were inferred which worked fine in the examples inside the
project but when compiled as lib, causes a problem were the functions inside the traits can not
correctly infer the store , this also fixes using the library with skipLibCheck: false

Fixes #145 , #91
gabrielguerrero pushed a commit that referenced this issue Oct 1, 2024
Made the return type explicit for withSyncToWebStorage, withStateLogger and
withSyncToRouteQueryParams, before the were inferred which worked fine in the examples inside the
project but when compiled as lib, causes a problem were the functions inside the traits can not
correctly infer the store , this also fixes using the library with skipLibCheck: false
Added missing docs, for typedCallConfig

Fixes #145 , #91
Copy link

github-actions bot commented Oct 1, 2024

🎉 This issue has been resolved in version 18.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant