{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/2892","repository_url":"https://api.github.com/repos/facebook/flow","labels_url":"https://api.github.com/repos/facebook/flow/issues/2892/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/2892/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/2892/events","html_url":"https://github.com/facebook/flow/issues/2892","id":191680119,"number":2892,"title":"Could not decide which case to select","user":{"login":"stijnvanderlaan","id":20322260,"avatar_url":"https://avatars.githubusercontent.com/u/20322260?v=3","gravatar_id":"","url":"https://api.github.com/users/stijnvanderlaan","html_url":"https://github.com/stijnvanderlaan","followers_url":"https://api.github.com/users/stijnvanderlaan/followers","following_url":"https://api.github.com/users/stijnvanderlaan/following{/other_user}","gists_url":"https://api.github.com/users/stijnvanderlaan/gists{/gist_id}","starred_url":"https://api.github.com/users/stijnvanderlaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stijnvanderlaan/subscriptions","organizations_url":"https://api.github.com/users/stijnvanderlaan/orgs","repos_url":"https://api.github.com/users/stijnvanderlaan/repos","events_url":"https://api.github.com/users/stijnvanderlaan/events{/privacy}","received_events_url":"https://api.github.com/users/stijnvanderlaan/received_events","type":"User","site_admin":false},"labels":[{"id":142478706,"url":"https://api.github.com/repos/facebook/flow/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-25T11:18:40Z","updated_at":"2016-11-25T12:42:29Z","closed_at":null,"body":"This\r\n```\r\nexport type InitState = {\r\n  type: \"init\",\r\n  lang: string,\r\n}\r\n\r\nexport type SecondState = {\r\n  type: \"second\",\r\n  lang: string,\r\n}\r\n\r\nexport type State = InitState | SecondState\r\n\r\nconst transform = (input:State, lang:string) : State => {\r\n  return {\r\n    ...input,\r\n    lang\r\n  }\r\n}\r\n\r\nlet state: State = {\r\n  type: \"init\",\r\n  lang: \"en\"\r\n}\r\n\r\nlet state2 = transform(state, \"nl\")\r\n\r\n```\r\nResults in the next error.\r\n\r\n```\r\n 47:   return {\r\n              ^ object literal. Could not decide which case to select\r\n 46: const transform = (input:State, lang:string) : State => {\r\n                                                    ^^^^^ union type\r\n  Case 1 may work:\r\n   44: export type State = InitState | SecondState\r\n                           ^^^^^^^^^ InitState\r\n  But if it doesn't, case 2 looks promising too:\r\n   44: export type State = InitState | SecondState\r\n                                       ^^^^^^^^^^^ SecondState\r\n  Please provide additional annotation(s) to determine whether case 1 works (or consider merging it with case 2):\r\n  .type\r\n\r\n```\r\n\r\nAl the cases have `lang`, so I think it should return the same type as it gets, like the next situation, which works fine:\r\n\r\n```\r\nconst transform = (input:State, lang:string) : State => {\r\n  return input\r\n}\r\n```\r\n\r\nCasting the output to `State` or `typeof input` those not resolve the issue."},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/262950377","html_url":"https://github.com/facebook/flow/issues/2892#issuecomment-262950377","issue_url":"https://api.github.com/repos/facebook/flow/issues/2892","id":262950377,"user":{"login":"stijnvanderlaan","id":20322260,"avatar_url":"https://avatars.githubusercontent.com/u/20322260?v=3","gravatar_id":"","url":"https://api.github.com/users/stijnvanderlaan","html_url":"https://github.com/stijnvanderlaan","followers_url":"https://api.github.com/users/stijnvanderlaan/followers","following_url":"https://api.github.com/users/stijnvanderlaan/following{/other_user}","gists_url":"https://api.github.com/users/stijnvanderlaan/gists{/gist_id}","starred_url":"https://api.github.com/users/stijnvanderlaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stijnvanderlaan/subscriptions","organizations_url":"https://api.github.com/users/stijnvanderlaan/orgs","repos_url":"https://api.github.com/users/stijnvanderlaan/repos","events_url":"https://api.github.com/users/stijnvanderlaan/events{/privacy}","received_events_url":"https://api.github.com/users/stijnvanderlaan/received_events","type":"User","site_admin":false},"created_at":"2016-11-25T12:42:29Z","updated_at":"2016-11-25T12:42:29Z","body":"But when `SecondState` has additional parameters you have to make them optional because of this `transform`. This situation is just a illustration what happens in redux when `transform` is a reducer. It would be great to have a reducer with differente states, and be able te change the state without actually knowing which state you are because al cases are compatible."}}
{"actor":{"display_login":"stijnvanderlaan"}}