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

Typings for function binding an action does not allow async #198

Open
jschill opened this issue Oct 7, 2022 · 0 comments
Open

Typings for function binding an action does not allow async #198

jschill opened this issue Oct 7, 2022 · 0 comments

Comments

@jschill
Copy link

jschill commented Oct 7, 2022

When binding a function manually....

import createStore from 'unistore'

const store = createStore({ count: 0, stuff: [] })

const myAsyncAction = async (state, store) => {
  await somethingAsync()
  ....
};

...and do the actual binding

const myBoundAsyncAction = store.action(myAsyncAction)

It will result in..
Promise returned in function argument where a void return was expected.eslint[@typescript-eslint/no-misused-promises](https://typescript-eslint.io/rules/no-misused-promises)
...because the typings does not allow for an async function.

A suggested fix would be to type Action the same way as ActionFn but with the addition of Promise<void> (which should also be added to ActionFn i guess). Ie:

export type Action<K> = (state: K, ...args: any[]) => Promise<Partial<K>> | Partial<K> | Promise<void> | void;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant