Skip to content

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

Description

@jschill

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;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions