{"action":"created","comment":{"url":"https://api.github.com/repos/gaearon/redux-thunk/pulls/comments/173346200","pull_request_review_id":102523543,"id":173346200,"diff_hunk":"@@ -1,33 +1,68 @@\n-import {Store, Middleware} from 'redux';\n-import thunk, {ThunkAction} from '../index.d.ts';\n+import { createStore, applyMiddleware } from 'redux';\n+import thunk, { ThunkAction, ThunkMiddleware } from '../index';\n \n+type State = {\n+  foo: string;\n+};\n \n-declare const store: Store<{foo: string}>;\n+type Actions = { type: 'FOO' } | { type: 'BAR', result: number };\n \n-store.dispatch(dispatch => {\n-  dispatch({type: 'FOO'});\n-});\n+type ThunkResult<R> = ThunkAction<R, State, undefined, Actions>;\n \n-store.dispatch((dispatch, getState) => {\n-  const state = getState();\n+const initialState: State = {\n+  foo: 'foo'\n+};\n \n-  const foo: string = state.foo;\n-});\n+function fakeReducer(state: State = initialState, action: Actions): State {\n+  return state;\n+}\n \n-const middleware: Middleware = thunk.withExtraArgument('bar');\n+const store = createStore(fakeReducer, applyMiddleware(thunk as ThunkMiddleware<State, Actions>));","path":"test/typescript.ts","position":31,"original_position":31,"commit_id":"f86bd3f343a420e880590e74c1f139f197fb9a55","original_commit_id":"f86bd3f343a420e880590e74c1f139f197fb9a55","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},"body":"I guess there's no need to declare `store` as `Store` because `Store` is a generic type. If you use `Store` alone without specifying types, default `dispatch` signature would be used. However, `createStore` returns a `Store` where most generic constraints could be specified, which should be sounder in terms of typing in your case.","created_at":"2018-03-09T01:47:30Z","updated_at":"2018-03-09T01:47:30Z","html_url":"https://github.com/gaearon/redux-thunk/pull/180#discussion_r173346200","pull_request_url":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/gaearon/redux-thunk/pulls/comments/173346200"},"html":{"href":"https://github.com/gaearon/redux-thunk/pull/180#discussion_r173346200"},"pull_request":{"href":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180"}},"in_reply_to_id":173176067},"pull_request":{"url":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180","id":171584056,"html_url":"https://github.com/gaearon/redux-thunk/pull/180","diff_url":"https://github.com/gaearon/redux-thunk/pull/180.diff","patch_url":"https://github.com/gaearon/redux-thunk/pull/180.patch","issue_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/180","number":180,"state":"open","locked":false,"title":"Make typings compatible with Redux 4.0.0-beta.2","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},"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","created_at":"2018-02-27T07:35:13Z","updated_at":"2018-03-09T01:47:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ffc892971a33b50298682de4dc14cc436c6b93c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180/commits","review_comments_url":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180/comments","review_comment_url":"https://api.github.com/repos/gaearon/redux-thunk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/180/comments","statuses_url":"https://api.github.com/repos/gaearon/redux-thunk/statuses/f86bd3f343a420e880590e74c1f139f197fb9a55","head":{"label":"Cryrivers:master","ref":"master","sha":"f86bd3f343a420e880590e74c1f139f197fb9a55","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},"repo":{"id":122929588,"name":"redux-thunk","full_name":"Cryrivers/redux-thunk","owner":{"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},"private":false,"html_url":"https://github.com/Cryrivers/redux-thunk","description":"Thunk middleware for Redux","fork":true,"url":"https://api.github.com/repos/Cryrivers/redux-thunk","forks_url":"https://api.github.com/repos/Cryrivers/redux-thunk/forks","keys_url":"https://api.github.com/repos/Cryrivers/redux-thunk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Cryrivers/redux-thunk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Cryrivers/redux-thunk/teams","hooks_url":"https://api.github.com/repos/Cryrivers/redux-thunk/hooks","issue_events_url":"https://api.github.com/repos/Cryrivers/redux-thunk/issues/events{/number}","events_url":"https://api.github.com/repos/Cryrivers/redux-thunk/events","assignees_url":"https://api.github.com/repos/Cryrivers/redux-thunk/assignees{/user}","branches_url":"https://api.github.com/repos/Cryrivers/redux-thunk/branches{/branch}","tags_url":"https://api.github.com/repos/Cryrivers/redux-thunk/tags","blobs_url":"https://api.github.com/repos/Cryrivers/redux-thunk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Cryrivers/redux-thunk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Cryrivers/redux-thunk/git/refs{/sha}","trees_url":"https://api.github.com/repos/Cryrivers/redux-thunk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Cryrivers/redux-thunk/statuses/{sha}","languages_url":"https://api.github.com/repos/Cryrivers/redux-thunk/languages","stargazers_url":"https://api.github.com/repos/Cryrivers/redux-thunk/stargazers","contributors_url":"https://api.github.com/repos/Cryrivers/redux-thunk/contributors","subscribers_url":"https://api.github.com/repos/Cryrivers/redux-thunk/subscribers","subscription_url":"https://api.github.com/repos/Cryrivers/redux-thunk/subscription","commits_url":"https://api.github.com/repos/Cryrivers/redux-thunk/commits{/sha}","git_commits_url":"https://api.github.com/repos/Cryrivers/redux-thunk/git/commits{/sha}","comments_url":"https://api.github.com/repos/Cryrivers/redux-thunk/comments{/number}","issue_comment_url":"https://api.github.com/repos/Cryrivers/redux-thunk/issues/comments{/number}","contents_url":"https://api.github.com/repos/Cryrivers/redux-thunk/contents/{+path}","compare_url":"https://api.github.com/repos/Cryrivers/redux-thunk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Cryrivers/redux-thunk/merges","archive_url":"https://api.github.com/repos/Cryrivers/redux-thunk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Cryrivers/redux-thunk/downloads","issues_url":"https://api.github.com/repos/Cryrivers/redux-thunk/issues{/number}","pulls_url":"https://api.github.com/repos/Cryrivers/redux-thunk/pulls{/number}","milestones_url":"https://api.github.com/repos/Cryrivers/redux-thunk/milestones{/number}","notifications_url":"https://api.github.com/repos/Cryrivers/redux-thunk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Cryrivers/redux-thunk/labels{/name}","releases_url":"https://api.github.com/repos/Cryrivers/redux-thunk/releases{/id}","deployments_url":"https://api.github.com/repos/Cryrivers/redux-thunk/deployments","created_at":"2018-02-26T07:20:30Z","updated_at":"2018-02-26T07:20:31Z","pushed_at":"2018-03-06T07:10:51Z","git_url":"git://github.com/Cryrivers/redux-thunk.git","ssh_url":"git@github.com:Cryrivers/redux-thunk.git","clone_url":"https://github.com/Cryrivers/redux-thunk.git","svn_url":"https://github.com/Cryrivers/redux-thunk","homepage":null,"size":78,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"gaearon:master","ref":"master","sha":"4f96ec0239453623adde857b7e7ad8c4f2897bf1","user":{"login":"gaearon","id":810438,"avatar_url":"https://avatars0.githubusercontent.com/u/810438?v=4","gravatar_id":"","url":"https://api.github.com/users/gaearon","html_url":"https://github.com/gaearon","followers_url":"https://api.github.com/users/gaearon/followers","following_url":"https://api.github.com/users/gaearon/following{/other_user}","gists_url":"https://api.github.com/users/gaearon/gists{/gist_id}","starred_url":"https://api.github.com/users/gaearon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaearon/subscriptions","organizations_url":"https://api.github.com/users/gaearon/orgs","repos_url":"https://api.github.com/users/gaearon/repos","events_url":"https://api.github.com/users/gaearon/events{/privacy}","received_events_url":"https://api.github.com/users/gaearon/received_events","type":"User","site_admin":false},"repo":{"id":39013909,"name":"redux-thunk","full_name":"gaearon/redux-thunk","owner":{"login":"gaearon","id":810438,"avatar_url":"https://avatars0.githubusercontent.com/u/810438?v=4","gravatar_id":"","url":"https://api.github.com/users/gaearon","html_url":"https://github.com/gaearon","followers_url":"https://api.github.com/users/gaearon/followers","following_url":"https://api.github.com/users/gaearon/following{/other_user}","gists_url":"https://api.github.com/users/gaearon/gists{/gist_id}","starred_url":"https://api.github.com/users/gaearon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaearon/subscriptions","organizations_url":"https://api.github.com/users/gaearon/orgs","repos_url":"https://api.github.com/users/gaearon/repos","events_url":"https://api.github.com/users/gaearon/events{/privacy}","received_events_url":"https://api.github.com/users/gaearon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gaearon/redux-thunk","description":"Thunk middleware for Redux","fork":false,"url":"https://api.github.com/repos/gaearon/redux-thunk","forks_url":"https://api.github.com/repos/gaearon/redux-thunk/forks","keys_url":"https://api.github.com/repos/gaearon/redux-thunk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gaearon/redux-thunk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gaearon/redux-thunk/teams","hooks_url":"https://api.github.com/repos/gaearon/redux-thunk/hooks","issue_events_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/events{/number}","events_url":"https://api.github.com/repos/gaearon/redux-thunk/events","assignees_url":"https://api.github.com/repos/gaearon/redux-thunk/assignees{/user}","branches_url":"https://api.github.com/repos/gaearon/redux-thunk/branches{/branch}","tags_url":"https://api.github.com/repos/gaearon/redux-thunk/tags","blobs_url":"https://api.github.com/repos/gaearon/redux-thunk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gaearon/redux-thunk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gaearon/redux-thunk/git/refs{/sha}","trees_url":"https://api.github.com/repos/gaearon/redux-thunk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gaearon/redux-thunk/statuses/{sha}","languages_url":"https://api.github.com/repos/gaearon/redux-thunk/languages","stargazers_url":"https://api.github.com/repos/gaearon/redux-thunk/stargazers","contributors_url":"https://api.github.com/repos/gaearon/redux-thunk/contributors","subscribers_url":"https://api.github.com/repos/gaearon/redux-thunk/subscribers","subscription_url":"https://api.github.com/repos/gaearon/redux-thunk/subscription","commits_url":"https://api.github.com/repos/gaearon/redux-thunk/commits{/sha}","git_commits_url":"https://api.github.com/repos/gaearon/redux-thunk/git/commits{/sha}","comments_url":"https://api.github.com/repos/gaearon/redux-thunk/comments{/number}","issue_comment_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/comments{/number}","contents_url":"https://api.github.com/repos/gaearon/redux-thunk/contents/{+path}","compare_url":"https://api.github.com/repos/gaearon/redux-thunk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gaearon/redux-thunk/merges","archive_url":"https://api.github.com/repos/gaearon/redux-thunk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gaearon/redux-thunk/downloads","issues_url":"https://api.github.com/repos/gaearon/redux-thunk/issues{/number}","pulls_url":"https://api.github.com/repos/gaearon/redux-thunk/pulls{/number}","milestones_url":"https://api.github.com/repos/gaearon/redux-thunk/milestones{/number}","notifications_url":"https://api.github.com/repos/gaearon/redux-thunk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gaearon/redux-thunk/labels{/name}","releases_url":"https://api.github.com/repos/gaearon/redux-thunk/releases{/id}","deployments_url":"https://api.github.com/repos/gaearon/redux-thunk/deployments","created_at":"2015-07-13T13:33:08Z","updated_at":"2018-03-08T22:59:15Z","pushed_at":"2018-03-06T07:09:35Z","git_url":"git://github.com/gaearon/redux-thunk.git","ssh_url":"git@github.com:gaearon/redux-thunk.git","clone_url":"https://github.com/gaearon/redux-thunk.git","svn_url":"https://github.com/gaearon/redux-thunk","homepage":null,"size":42,"stargazers_count":8113,"watchers_count":8113,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":378,"mirror_url":null,"archived":false,"open_issues_count":66,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":378,"open_issues":66,"watchers":8113,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180"},"html":{"href":"https://github.com/gaearon/redux-thunk/pull/180"},"issue":{"href":"https://api.github.com/repos/gaearon/redux-thunk/issues/180"},"comments":{"href":"https://api.github.com/repos/gaearon/redux-thunk/issues/180/comments"},"review_comments":{"href":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180/comments"},"review_comment":{"href":"https://api.github.com/repos/gaearon/redux-thunk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gaearon/redux-thunk/pulls/180/commits"},"statuses":{"href":"https://api.github.com/repos/gaearon/redux-thunk/statuses/f86bd3f343a420e880590e74c1f139f197fb9a55"}},"author_association":"NONE"}}
{"actor":{"display_login":"Cryrivers"}}