Title: Typings for function binding an action does not allow async · Issue #198 · developit/unistore · GitHub
Open Graph Title: Typings for function binding an action does not allow async · Issue #198 · developit/unistore
X Title: Typings for function binding an action does not allow async · Issue #198 · developit/unistore
Description: 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 ...
Open Graph Description: When binding a function manually.... import createStore from 'unistore' const store = createStore({ count: 0, stuff: [] }) const myAsyncAction = async (state, store) => { await somethingAsync() ......
X Description: When binding a function manually.... import createStore from 'unistore' const store = createStore({ count: 0, stuff: [] }) const myAsyncAction = async (state, store) => { await something...
Opengraph URL: https://github.com/developit/unistore/issues/198
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Typings for function binding an action does not allow async","articleBody":"When binding a function manually....\r\n\r\n```js\r\nimport createStore from 'unistore'\r\n\r\nconst store = createStore({ count: 0, stuff: [] })\r\n\r\nconst myAsyncAction = async (state, store) =\u003e {\r\n await somethingAsync()\r\n ....\r\n};\r\n```\r\n...and do the actual binding\r\n```js\r\nconst myBoundAsyncAction = store.action(myAsyncAction)\r\n```\r\nIt will result in..\r\n`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)`\r\n...because [the typings](https://github.com/developit/unistore/blob/f3a4e99d4c62b27773fa2e520998e55f129f3819/index.d.ts#L8) does not allow for an async function.\r\n\r\nA suggested fix would be to type `Action` the same way as `ActionFn` but with the addition of `Promise\u003cvoid\u003e` (which should also be added to ActionFn i guess). Ie:\r\n\r\n```js\r\nexport type Action\u003cK\u003e = (state: K, ...args: any[]) =\u003e Promise\u003cPartial\u003cK\u003e\u003e | Partial\u003cK\u003e | Promise\u003cvoid\u003e | void;\r\n```","author":{"url":"https://github.com/jschill","@type":"Person","name":"jschill"},"datePublished":"2022-10-07T09:45:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/198/unistore/issues/198"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:73c8570a-25c6-d291-b339-91e9ba7debb2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8FFE:1DE5:567C80:6CA3E0:6990C774 |
| html-safe-nonce | c4793ce81fcdb0e682a520b5e8842fba3484ee80764946753b12282c2a5b9c45 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkZFOjFERTU6NTY3QzgwOjZDQTNFMDo2OTkwQzc3NCIsInZpc2l0b3JfaWQiOiIzNTI4NTE1MjI2ODYwMzA4MzQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 741e253420b61fc4d59678c20d8c0b8af0eab84cafc90c71e1660cbc340b0e02 |
| hovercard-subject-tag | issue:1400907786 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developit/unistore/198/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b07fb1c82dacbdecdf9559812ee94366033a91660c86a821b8526a9d0d791ea9/developit/unistore/issues/198 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b07fb1c82dacbdecdf9559812ee94366033a91660c86a821b8526a9d0d791ea9/developit/unistore/issues/198 |
| og:image:alt | When binding a function manually.... import createStore from 'unistore' const store = createStore({ count: 0, stuff: [] }) const myAsyncAction = async (state, store) => { await somethingAsync() ...... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jschill |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/developit/unistore git https://github.com/developit/unistore.git |
| octolytics-dimension-user_id | 105127 |
| octolytics-dimension-user_login | developit |
| octolytics-dimension-repository_id | 113351554 |
| octolytics-dimension-repository_nwo | developit/unistore |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 113351554 |
| octolytics-dimension-repository_network_root_nwo | developit/unistore |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width