{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/4417","repository_url":"https://api.github.com/repos/facebook/flow","labels_url":"https://api.github.com/repos/facebook/flow/issues/4417/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/4417/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/4417/events","html_url":"https://github.com/facebook/flow/issues/4417","id":243949434,"number":4417,"title":"Function cannot be called on any member of intersection type","user":{"login":"barbu110","id":7272395,"avatar_url":"https://avatars0.githubusercontent.com/u/7272395?v=4","gravatar_id":"","url":"https://api.github.com/users/barbu110","html_url":"https://github.com/barbu110","followers_url":"https://api.github.com/users/barbu110/followers","following_url":"https://api.github.com/users/barbu110/following{/other_user}","gists_url":"https://api.github.com/users/barbu110/gists{/gist_id}","starred_url":"https://api.github.com/users/barbu110/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barbu110/subscriptions","organizations_url":"https://api.github.com/users/barbu110/orgs","repos_url":"https://api.github.com/users/barbu110/repos","events_url":"https://api.github.com/users/barbu110/events{/privacy}","received_events_url":"https://api.github.com/users/barbu110/received_events","type":"User","site_admin":false},"labels":[{"id":650840873,"url":"https://api.github.com/repos/facebook/flow/labels/Closed:%20not%20a%20bug","name":"Closed: not a bug","color":"ffffff","default":false},{"id":650840457,"url":"https://api.github.com/repos/facebook/flow/labels/Support","name":"Support","color":"5319e7","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-19T07:40:44Z","updated_at":"2017-07-20T00:40:13Z","closed_at":"2017-07-20T00:40:13Z","body":"Hi guys!\r\n\r\nI am trying to set up typechecking for the following file:\r\n\r\n```js\r\n// @flow\r\n\r\nimport { createStore as c, applyMiddleware, compose } from 'redux';\r\nimport thunkMiddleware from 'redux-thunk';\r\nimport type { CombinedReducer } from 'redux';\r\nimport { composeWithDevTools } from 'redux-devtools-extension';\r\n\r\nexport default function createStore(\r\n    reducer: CombinedReducer<*, *>,\r\n    preloadedState: *,\r\n) {\r\n    return c(\r\n        reducer,\r\n        preloadedState,\r\n        composeWithDevTools(applyMiddleware(\r\n            thunkMiddleware,\r\n        ))\r\n    );\r\n}\r\n```\r\n\r\nI think the best way for doing it is by setting `createStore` to be a template function. So I tried this:\r\n\r\n```js\r\nfunction createStore<S>(\r\n  reducer: CombinedReducer<S, *>,\r\n  preloadedState: S,\r\n) { /* ... */ }\r\n```\r\n\r\nI get the following errors:\r\n\r\n```\r\nLibrary type error:\r\nflow-typed/npm/redux_v3.x.x.js:54\r\n 54:   declare function combineReducers<O: Object, A>(reducers: O): CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;\r\n                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ object map\r\n                  v\r\n 14:       return {\r\n 15:         loading: false,\r\n 16:         user: action.user,\r\n 17:       };\r\n           ^ object literal. This type is incompatible with. See: resources/client/reducers/user.js:14\r\n  7: export default function user(state: UserState = {loading: true}, action: Object) {\r\n                                         ^^^^^^^^^ union: exact type: object type(s). See: resources/client/reducers/user.js:7\r\n  Member 1:\r\n                                       v-\r\n    3: export type AsyncStructure<T> = {|\r\n    4:     loading: true\r\n    5: |} | {|\r\n       -^ exact type: object type. See: resources/client/@types/AsyncStructure.js:3\r\n  Error:\r\n                    v\r\n   14:       return {\r\n   15:         loading: false,\r\n   16:         user: action.user,\r\n   17:       };\r\n             ^ property `user`. Property not found in. See: resources/client/reducers/user.js:14\r\n                                       v-\r\n    3: export type AsyncStructure<T> = {|\r\n    4:     loading: true\r\n    5: |} | {|\r\n       -^ object type. See: resources/client/@types/AsyncStructure.js:3\r\n  Member 2:\r\n            v-\r\n    5: |} | {|\r\n    6:     loading: false,\r\n    7:     data: T,\r\n    8: |};\r\n       -^ exact type: object type. See: resources/client/@types/AsyncStructure.js:5\r\n  Error:\r\n                    v\r\n   14:       return {\r\n   15:         loading: false,\r\n   16:         user: action.user,\r\n   17:       };\r\n             ^ property `user`. Property not found in. See: resources/client/reducers/user.js:14\r\n            v-\r\n    5: |} | {|\r\n    6:     loading: false,\r\n    7:     data: T,\r\n    8: |};\r\n       -^ object type. See: resources/client/@types/AsyncStructure.js:5\r\n\r\nresources/client/reducers/ui.js:7\r\n  7: const defaultState: UiState = {\r\n                         ^^^^^^^ property `mediaQuery`. Property not found in\r\n                                   v\r\n  7: const defaultState: UiState = {\r\n  8:   side: {\r\n  9:     visible: true,\r\n...:\r\n 14: };\r\n     ^ object literal\r\n\r\nresources/client/stores/createStore.js:13\r\n                v-\r\n 13:     return c(\r\n 14:         reducer,\r\n 15:         preloadedState,\r\n...:\r\n 19:     );\r\n         ^ function call. Function cannot be called on any member of intersection type\r\n 13:     return c(\r\n                ^ intersection\r\n  Member 1:\r\n   43:   declare function createStore<S, A>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A>): Store<S, A>;\r\n                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ polymorphic type: function type. See lib: flow-typed/npm/redux_v3.x.x.js:43\r\n  Error:\r\n    9: export default function createStore<S>(\r\n                                           ^ S. This type is incompatible with\r\n   30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                      ^^^^^^^^^^^^^^^^^^^^^ union: intersection type | undefined. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n    Member 1:\r\n     30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                        ^^^^^^^^^^^^^^ intersection type. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n    Error:\r\n      9: export default function createStore<S>(\r\n                                             ^ S. Expected object instead of\r\n      9: export default function createStore<S>(\r\n                                             ^ S\r\n    Member 2:\r\n     30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                                         ^^^^ undefined. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n    Error:\r\n      9: export default function createStore<S>(\r\n                                             ^ S. This type is incompatible with\r\n     30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                                         ^^^^ undefined. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n  Member 2:\r\n   44:   declare function createStore<S, A>(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A>): Store<S, A>;\r\n                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ polymorphic type: function type. See lib: flow-typed/npm/redux_v3.x.x.js:44\r\n  Error:\r\n    9: export default function createStore<S>(\r\n                                           ^ S. This type is incompatible with\r\n   30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                      ^^^^^^^^^^^^^^^^^^^^^ union: intersection type | undefined. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n    Member 1:\r\n     30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                        ^^^^^^^^^^^^^^ intersection type. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n    Error:\r\n      9: export default function createStore<S>(\r\n                                             ^ S. Expected object instead of\r\n      9: export default function createStore<S>(\r\n                                             ^ S\r\n    Member 2:\r\n     30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                                         ^^^^ undefined. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n    Error:\r\n      9: export default function createStore<S>(\r\n                                             ^ S. This type is incompatible with\r\n     30:   declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;\r\n                                                                         ^^^^ undefined. See lib: flow-typed/npm/redux_v3.x.x.js:30\r\n\r\n```\r\n\r\nCould you please help me setting up the typechecking for this function?"},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/316563018","html_url":"https://github.com/facebook/flow/issues/4417#issuecomment-316563018","issue_url":"https://api.github.com/repos/facebook/flow/issues/4417","id":316563018,"user":{"login":"billschaller","id":4266849,"avatar_url":"https://avatars1.githubusercontent.com/u/4266849?v=4","gravatar_id":"","url":"https://api.github.com/users/billschaller","html_url":"https://github.com/billschaller","followers_url":"https://api.github.com/users/billschaller/followers","following_url":"https://api.github.com/users/billschaller/following{/other_user}","gists_url":"https://api.github.com/users/billschaller/gists{/gist_id}","starred_url":"https://api.github.com/users/billschaller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billschaller/subscriptions","organizations_url":"https://api.github.com/users/billschaller/orgs","repos_url":"https://api.github.com/users/billschaller/repos","events_url":"https://api.github.com/users/billschaller/events{/privacy}","received_events_url":"https://api.github.com/users/billschaller/received_events","type":"User","site_admin":false},"created_at":"2017-07-20T00:40:13Z","updated_at":"2017-07-20T00:40:13Z","body":"Take a close look at the type defs for createStore: https://github.com/flowtype/flow-typed/blob/master/definitions/npm/redux_v3.x.x/flow_v0.33.x-/redux_v3.x.x.js#L40\r\n\r\nIt looks like something is messed up with the type defs on one of your reducers - are you passing in the result of combineReducers? Try eliminating parts of your root reducer until your flow errors go away, and that will help you narrow down which reducer is incorrectly typed.\r\n\r\nIf you have further issues, please create an example/repro using https://flow.org/try/ and post a question on StackOverflow (https://stackoverflow.com/questions/tagged/flowtype)."}}
{"actor":{"display_login":"billschaller"}}