{"action":"created","issue":{"url":"https://api.github.com/repos/reduxjs/redux-thunk/issues/180","repository_url":"https://api.github.com/repos/reduxjs/redux-thunk","labels_url":"https://api.github.com/repos/reduxjs/redux-thunk/issues/180/labels{/name}","comments_url":"https://api.github.com/repos/reduxjs/redux-thunk/issues/180/comments","events_url":"https://api.github.com/repos/reduxjs/redux-thunk/issues/180/events","html_url":"https://github.com/reduxjs/redux-thunk/pull/180","id":300521752,"number":180,"title":"Make typings compatible with Redux 4.0.0","user":{"login":"Cryrivers","id":1313238,"avatar_url":"https://avatars2.githubusercontent.com/u/1313238?v=4","gravatar_id":"","url":"https://api.github.com/users/Cryrivers","html_url":"https://github.com/Cryrivers","followers_url":"https://api.github.com/users/Cryrivers/followers","following_url":"https://api.github.com/users/Cryrivers/following{/other_user}","gists_url":"https://api.github.com/users/Cryrivers/gists{/gist_id}","starred_url":"https://api.github.com/users/Cryrivers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cryrivers/subscriptions","organizations_url":"https://api.github.com/users/Cryrivers/orgs","repos_url":"https://api.github.com/users/Cryrivers/repos","events_url":"https://api.github.com/users/Cryrivers/events{/privacy}","received_events_url":"https://api.github.com/users/Cryrivers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":45,"created_at":"2018-02-27T07:35:13Z","updated_at":"2018-05-24T23:01:08Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/reduxjs/redux-thunk/pulls/180","html_url":"https://github.com/reduxjs/redux-thunk/pull/180","diff_url":"https://github.com/reduxjs/redux-thunk/pull/180.diff","patch_url":"https://github.com/reduxjs/redux-thunk/pull/180.patch"},"body":"Partially fixes #169.\r\n\r\n**BREAKING**: It only supports TypeScript 2.4.0 or later.\r\n\r\nChanged `ThunkAction<R, S, E>` to `ThunkAction<R, S, E, A>`, where `R` is the return type of the thunk function, `S` is the type of root state, `E` is the type of extra arguments, `A` should be all actions that can be dispatched.\r\n\r\n~Due to the limitation of current implementation, I'm not sure if `R`, `S`, `E`, `A` could be inferred.~ (**UPDATE**: I changed the implementation a little bit. I believe `R`, `S`, `E`, could be inferred in `store.dispatch()`. Changes needed in type definition for `redux` to make `A` inferable. )So a potentially better solution is to create a type for thunk actions by yourself and specify root states and all actions that can be dispatched.\r\n\r\nExample:\r\n```ts\r\ntype SideEffect<T> = ThunkAction<Promise<T>, RootState, {}, RootAction>\r\n```\r\nHere I assume all my thunk functions return a promise of something. Then my thunk function returns a `SideEffect<T>`.\r\n\r\n```ts\r\nexport function asyncFunc(): SideEffect<string> {\r\n  return async (dispatch, getState) => {\r\n    dispatch({ type: ActionTypes.ASYNC });\r\n    await timeout(1000);\r\n    dispatch({ type: ActionTypes.ASYNC_FULFILLED });\r\n    await timeout(1000);\r\n    dispatch({ type: 'INVALID_ACTION_TYPE' });\r\n    return 'NICE!';\r\n  };\r\n}\r\n```\r\n\r\nThen you can check the typings of `dispatch` and `getState`.\r\n\r\n<img src=\"https://user-images.githubusercontent.com/1313238/36715975-a1a7fc22-1bd3-11e8-937f-f6e6b108e4a5.png\" width=\"500\" />\r\n\r\n<img src=\"https://user-images.githubusercontent.com/1313238/36715981-a9d69af2-1bd3-11e8-9a7a-d371247facde.png\" width=\"500\" />\r\n\r\nNaturally it also makes dispatching type-safe, too.\r\n\r\n<img src=\"https://user-images.githubusercontent.com/1313238/36716010-c61836a8-1bd3-11e8-8728-1c03c2cc6426.png\" width=\"400\" />\r\n"},"comment":{"url":"https://api.github.com/repos/reduxjs/redux-thunk/issues/comments/391891723","html_url":"https://github.com/reduxjs/redux-thunk/pull/180#issuecomment-391891723","issue_url":"https://api.github.com/repos/reduxjs/redux-thunk/issues/180","id":391891723,"user":{"login":"NathanNZ","id":6608414,"avatar_url":"https://avatars0.githubusercontent.com/u/6608414?v=4","gravatar_id":"","url":"https://api.github.com/users/NathanNZ","html_url":"https://github.com/NathanNZ","followers_url":"https://api.github.com/users/NathanNZ/followers","following_url":"https://api.github.com/users/NathanNZ/following{/other_user}","gists_url":"https://api.github.com/users/NathanNZ/gists{/gist_id}","starred_url":"https://api.github.com/users/NathanNZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NathanNZ/subscriptions","organizations_url":"https://api.github.com/users/NathanNZ/orgs","repos_url":"https://api.github.com/users/NathanNZ/repos","events_url":"https://api.github.com/users/NathanNZ/events{/privacy}","received_events_url":"https://api.github.com/users/NathanNZ/received_events","type":"User","site_admin":false},"created_at":"2018-05-24T23:01:08Z","updated_at":"2018-05-24T23:01:08Z","author_association":"NONE","body":"@timdorr any progress on this? \r\n\r\nWe could always accept this pull request for now, and then move the types across to DT at a later time. I really feel like we should focus on having something useable now even if it isn't perfect - and then the migration is a different story that can be figured out at a less urgent pace."}}
{"actor":{"display_login":"NathanNZ"}}