{"action":"created","issue":{"url":"https://api.github.com/repos/pelotom/runtypes/issues/47","repository_url":"https://api.github.com/repos/pelotom/runtypes","labels_url":"https://api.github.com/repos/pelotom/runtypes/issues/47/labels{/name}","comments_url":"https://api.github.com/repos/pelotom/runtypes/issues/47/comments","events_url":"https://api.github.com/repos/pelotom/runtypes/issues/47/events","html_url":"https://github.com/pelotom/runtypes/issues/47","id":312902648,"number":47,"title":"Possible for union.match to support methods which return different type's ...?","user":{"login":"breathe","id":434034,"avatar_url":"https://avatars0.githubusercontent.com/u/434034?v=4","gravatar_id":"","url":"https://api.github.com/users/breathe","html_url":"https://github.com/breathe","followers_url":"https://api.github.com/users/breathe/followers","following_url":"https://api.github.com/users/breathe/following{/other_user}","gists_url":"https://api.github.com/users/breathe/gists{/gist_id}","starred_url":"https://api.github.com/users/breathe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breathe/subscriptions","organizations_url":"https://api.github.com/users/breathe/orgs","repos_url":"https://api.github.com/users/breathe/repos","events_url":"https://api.github.com/users/breathe/events{/privacy}","received_events_url":"https://api.github.com/users/breathe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-10T12:34:22Z","updated_at":"2018-04-11T16:42:19Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"It might be convenient if the match(...) method on union types were able to support functions which return different types ...\r\n\r\nMaybe it be possible to implement .match() in such a way as to support a signature like this ...?\r\n\r\n```\r\nexport interface Match2<A extends Rt, B extends Rt> {\r\n    <Z1, Z2>(a: Case<A, Z1>, b: Case<B, Z2>): Matcher2<A, B, Z1, Z2>;\r\n```\r\n\r\n\r\nInstead of:\r\n```\r\nexport interface Match2<A extends Rt, B extends Rt> {\r\n    <Z>(a: Case<A, Z>, b: Case<B, Z>): Matcher2<A, B, Z>;\r\n```\r\n\r\nI took a stab at it with below PR ...  Kind of ugly but seems to work?  Is this a better type for .match() maybe?  Without it the constraints on the functions provided to .match(...) are very tight ...\r\n\r\nStraw-man example of what doesn't work without this change ...:\r\n\r\n```\r\nconst Type1 = rt.Record({ status: rt.Literal('failure'), msg: rt.String });\r\nconst Type2 = rt.Record({\r\n  status: rt.Literal('success'),\r\n  username: rt.String,\r\n  authenticationState: rt.String,\r\n});\r\nconst Response = rt.Union(Type1, Type2);\r\n\r\nconst extracted = Response.match(\r\n  failure => {\r\n    return { status: failure.status, authenticationState: 'not_logged_in', data: { ...failure } };\r\n  },\r\n  success => {\r\n    return {\r\n      status: success.status,\r\n      authenticationState: success.authenticationState,\r\n      data: { ...success },\r\n    };\r\n  },\r\n);\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/pelotom/runtypes/issues/comments/380518622","html_url":"https://github.com/pelotom/runtypes/issues/47#issuecomment-380518622","issue_url":"https://api.github.com/repos/pelotom/runtypes/issues/47","id":380518622,"user":{"login":"breathe","id":434034,"avatar_url":"https://avatars0.githubusercontent.com/u/434034?v=4","gravatar_id":"","url":"https://api.github.com/users/breathe","html_url":"https://github.com/breathe","followers_url":"https://api.github.com/users/breathe/followers","following_url":"https://api.github.com/users/breathe/following{/other_user}","gists_url":"https://api.github.com/users/breathe/gists{/gist_id}","starred_url":"https://api.github.com/users/breathe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breathe/subscriptions","organizations_url":"https://api.github.com/users/breathe/orgs","repos_url":"https://api.github.com/users/breathe/repos","events_url":"https://api.github.com/users/breathe/events{/privacy}","received_events_url":"https://api.github.com/users/breathe/received_events","type":"User","site_admin":false},"created_at":"2018-04-11T16:42:18Z","updated_at":"2018-04-11T16:42:18Z","author_association":"CONTRIBUTOR","body":"Hmm -- Could something like this using the new conditional type's in 2.8 maybe work ...?\r\n\r\n```\r\nexport function match<A extends Rt, B extends Rt, Z>( tuple: Z extends [ (x: A) => infer U, (x: B) => infer U] ? U : never): Matcher2<A, B, Z>;\r\n```\r\n\r\nInstead of:\r\n```\r\nexport function match<A extends Rt, B extends Rt, Z>(\r\n  a: PairCase<A, Z>,\r\n  b: PairCase<B, Z>,\r\n): Matcher2<A, B, Z>;\r\n```\r\n"}}
{"actor":{"display_login":"breathe"}}