developit / developit/unistore
Typings for function binding an action does not allow async
- Dominant language
- JavaScript
- Stars
- 2.8k
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Description
When binding a function manually....
```js
import createStore from 'unistore'
const store = createStore({ count: 0, stuff: [] })
const myAsyncAction = async (state, store) => {
await somethingAsync()
....
};
```
...and do the actual binding
```js
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](https://github.com/developit/unistore/blob/f3a4e99d4c62b27773fa2e520998e55f129f3819/index.d.ts#L8) 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` (which should also be added to ActionFn i guess). Ie:
```js
export type Action = (state: K, ...args: any[]) => Promise> | Partial | Promise | void;
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.