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

a store instance is not assignable to type Store #500

Closed
posva opened this issue May 17, 2021 · 0 comments
Closed

a store instance is not assignable to type Store #500

posva opened this issue May 17, 2021 · 0 comments
Labels
bug Something isn't working typescript This issue is related to typings

Comments

@posva
Copy link
Member

posva commented May 17, 2021

#499 (reply in thread)

export const useSyncValueToStore = <
  TStore extends Store,
  TKey extends keyof TStore['$state']
>(
  propGetter: () => TStore[TKey],
  store: TStore,
  key: TKey
): void => {
  watch(
    propGetter,
    (propValue) => {
      store[key] = propValue
    },
    {
      immediate: true,
    }
  )
}

// should have proper type support
useSyncValueToStore(() => 'on' as const, store, 'a')
@posva posva added bug Something isn't working typescript This issue is related to typings labels May 17, 2021
@posva posva closed this as completed in 48523da May 17, 2021
posva added a commit that referenced this issue May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typescript This issue is related to typings
Projects
None yet
Development

No branches or pull requests

1 participant