{"action":"created","issue":{"url":"https://api.github.com/repos/gaearon/redux-thunk/issues/82","repository_url":"https://api.github.com/repos/gaearon/redux-thunk","labels_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/82/comments","events_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/82/events","html_url":"https://github.com/gaearon/redux-thunk/issues/82","id":164300476,"number":82,"title":"TypeScript Error in Middleware","user":{"login":"KingHenne","id":761683,"avatar_url":"https://avatars.githubusercontent.com/u/761683?v=3","gravatar_id":"","url":"https://api.github.com/users/KingHenne","html_url":"https://github.com/KingHenne","followers_url":"https://api.github.com/users/KingHenne/followers","following_url":"https://api.github.com/users/KingHenne/following{/other_user}","gists_url":"https://api.github.com/users/KingHenne/gists{/gist_id}","starred_url":"https://api.github.com/users/KingHenne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KingHenne/subscriptions","organizations_url":"https://api.github.com/users/KingHenne/orgs","repos_url":"https://api.github.com/users/KingHenne/repos","events_url":"https://api.github.com/users/KingHenne/events{/privacy}","received_events_url":"https://api.github.com/users/KingHenne/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-07-07T12:46:07Z","updated_at":"2016-12-01T08:44:36Z","closed_at":null,"body":"The overloading of `Dispatch` by `redux-thunk` breaks middlewares that only handle standard action objects (as apposed to thunks).\n\nExample:\n\n``` ts\nimport {Action, Dispatch, Middleware, Store} from 'redux';\nimport {IAppState} from '../reducers';\n\nexport const middleware: Middleware = (store: Store<IAppState>) => (next: Dispatch<IAppState>) => (action: Action) => {\n  // Do something with the action ...\n  next(action);\n};\n```\n\nThe resulting error is:\n\n```\nType '(store: Store<IAppState>) => (next: Dispatch<IAppState>) => (action: Action) => void' is not assignable to type 'Middleware'.\n  Type '(next: Dispatch<IAppState>) => (action: Action) => void' is not assignable to type '(next: Dispatch<any>) => Dispatch<any>'.\n    Type '(action: Action) => void' is not assignable to type 'Dispatch<any>'.\n      Types of parameters 'action' and 'asyncAction' are incompatible.\n        Type '(dispatch: Dispatch<any>, getState: () => any, extraArgument: any) => any' is not assignable to type 'Action'.\n          Property 'type' is missing in type '(dispatch: Dispatch<any>, getState: () => any, extraArgument: any) => any'.\n```\n\nA possible fix to remove the compiler error would be to declare a union type for the Action, i.e. `Action | Redux.ThunkAction<any, IAppState, any>`:\n\n``` ts\nexport const middleware: Middleware = (store: Store<IAppState>) => (next: Dispatch<IAppState>) => (action: Action | Redux.ThunkAction<any, IAppState, any>) => {\n  // Do something with the action ...\n  next(action as Action);\n};\n```\n\nBut this is incorrect if your middleware only handles `Action`!\n\nThe better solution would be to declare a `Dispatch` interface within the `redux-thunk` module that extends `Redux.Dispatch`. This `Dispatch` could then be used in action creators that return a `ThunkAction`:\n\n``` ts\nimport {IAppState} from '../reducers';\nimport {ThunkAction, Dispatch} from 'redux-thunk';\n\nexport function thunkedActionCreator(): ThunkAction<void, IAppState, void> {\n  return (dispatch: Dispatch<IAppState>, getState: () => IAppState): void => {\n    // Do something async and dispatch actions or other thunks ...\n  };\n}\n```\n\nMiddlewares on the other hand would use `Redux.Dispatch` (see middleware example above).\n"},"comment":{"url":"https://api.github.com/repos/gaearon/redux-thunk/issues/comments/264113285","html_url":"https://github.com/gaearon/redux-thunk/issues/82#issuecomment-264113285","issue_url":"https://api.github.com/repos/gaearon/redux-thunk/issues/82","id":264113285,"user":{"login":"born2net","id":5090936,"avatar_url":"https://avatars.githubusercontent.com/u/5090936?v=3","gravatar_id":"","url":"https://api.github.com/users/born2net","html_url":"https://github.com/born2net","followers_url":"https://api.github.com/users/born2net/followers","following_url":"https://api.github.com/users/born2net/following{/other_user}","gists_url":"https://api.github.com/users/born2net/gists{/gist_id}","starred_url":"https://api.github.com/users/born2net/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/born2net/subscriptions","organizations_url":"https://api.github.com/users/born2net/orgs","repos_url":"https://api.github.com/users/born2net/repos","events_url":"https://api.github.com/users/born2net/events{/privacy}","received_events_url":"https://api.github.com/users/born2net/received_events","type":"User","site_admin":false},"created_at":"2016-12-01T08:44:36Z","updated_at":"2016-12-01T08:44:36Z","body":"I am using the latest ts and still same issue of:\r\n\r\n```\r\nError:(13, 29) TS2345:Argument of type '(dispatch: any) => void' is not assignable to parameter of type 'Action'.\r\n  Property 'type' is missing in type '(dispatch: any) => void'.\r\n```\r\nas I am dispatching a thunk\r\n\r\nany ideas?\r\n"}}
{"actor":{"display_login":"born2net"}}