{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/26258","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/26258/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/26258/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/26258/events","html_url":"https://github.com/Microsoft/TypeScript/issues/26258","id":348333200,"node_id":"MDU6SXNzdWUzNDgzMzMyMDA=","number":26258,"title":"Discriminated union assignment won't compile inside function","user":{"login":"explosivose","id":4212114,"node_id":"MDQ6VXNlcjQyMTIxMTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/4212114?v=4","gravatar_id":"","url":"https://api.github.com/users/explosivose","html_url":"https://github.com/explosivose","followers_url":"https://api.github.com/users/explosivose/followers","following_url":"https://api.github.com/users/explosivose/following{/other_user}","gists_url":"https://api.github.com/users/explosivose/gists{/gist_id}","starred_url":"https://api.github.com/users/explosivose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/explosivose/subscriptions","organizations_url":"https://api.github.com/users/explosivose/orgs","repos_url":"https://api.github.com/users/explosivose/repos","events_url":"https://api.github.com/users/explosivose/events{/privacy}","received_events_url":"https://api.github.com/users/explosivose/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-08-07T13:57:22Z","updated_at":"2018-08-07T16:17:34Z","closed_at":null,"author_association":"NONE","body":"\r\n\r\n<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:**  3.1.0-dev.20180807\r\n\r\n<!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** union type, union type as function parameter, union type with string literal, discriminated union\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Iface1A {\r\n  type: \"A\";\r\n}\r\ninterface Iface1B {\r\n  type: \"B\";\r\n}\r\ninterface Iface1C {\r\n  type: \"C\";\r\n}\r\ntype Iface1 = Iface1A | Iface1B | Iface1C;\r\n\r\ninterface Iface2A {\r\n  type: \"A\";\r\n}\r\ninterface Iface2B {\r\n  type: \"B\";\r\n}\r\ninterface Iface2C {\r\n  type: \"C\";\r\n}\r\ntype Iface2 = Iface2A | Iface2B | Iface2C;\r\n\r\nconst obj1: Iface1 = {type: \"C\"}; // works\r\nconst obj2: Iface2 = {type: obj1.type}; // works\r\nconst func = (o1: Iface1) => {\r\n  const o2: Iface2 = {type: o1.type}; // compile error\r\n  // a workaround:\r\n  const o2: Iface2 = {type: o1.type as \"A\"}; \r\n  return o2;\r\n};\r\n```\r\n\r\n**Expected behavior:** No compile error - should be able to initialize `o2` with the member of `o1` as with `obj1` and `obj2`.\r\n\r\n**Actual behavior:** \r\n```\r\nindex.ts:26:9 - error TS2322: Type '{ type: \"A\" | \"B\" | \"C\"; }' is not assignable to type 'Iface2'.\r\n  Type '{ type: \"A\" | \"B\" | \"C\"; }' is not assignable to type 'Iface2C'.\r\n    Types of property 'type' are incompatible.\r\n      Type '\"A\" | \"B\" | \"C\"' is not assignable to type '\"C\"'.\r\n        Type '\"A\"' is not assignable to type '\"C\"'.\r\n```\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play/index.html#src=interface%20Iface1A%20%7B%0D%0A%20%20type%3A%20%22A%22%3B%0D%0A%7D%0D%0Ainterface%20Iface1B%20%7B%0D%0A%20%20type%3A%20%22B%22%3B%0D%0A%7D%0D%0Ainterface%20Iface1C%20%7B%0D%0A%20%20type%3A%20%22C%22%3B%0D%0A%7D%0D%0Atype%20Iface1%20%3D%20Iface1A%20%7C%20Iface1B%20%7C%20Iface1C%3B%0D%0A%0D%0Ainterface%20Iface2A%20%7B%0D%0A%20%20type%3A%20%22A%22%3B%0D%0A%7D%0D%0Ainterface%20Iface2B%20%7B%0D%0A%20%20type%3A%20%22B%22%3B%0D%0A%7D%0D%0Ainterface%20Iface2C%20%7B%0D%0A%20%20type%3A%20%22C%22%3B%0D%0A%7D%0D%0Atype%20Iface2%20%3D%20Iface2A%20%7C%20Iface2B%20%7C%20Iface2C%3B%0D%0A%0D%0Aconst%20obj1%3A%20Iface1%20%3D%20%7Btype%3A%20%22C%22%7D%3B%20%2F%2F%20works%0D%0Aconst%20obj2%3A%20Iface2%20%3D%20%7Btype%3A%20obj1.type%7D%3B%20%2F%2F%20works%0D%0Aconst%20func%20%3D%20(o1%3A%20Iface1)%20%3D%3E%20%7B%0D%0A%20%20const%20o2%3A%20Iface2%20%3D%20%7Btype%3A%20o1.type%7D%3B%20%2F%2F%20compile%20error%0D%0A%20%20return%20o2%3B%0D%0A%7D%3B\r\n\r\n**Related Issues:** \r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/411114919","html_url":"https://github.com/Microsoft/TypeScript/issues/26258#issuecomment-411114919","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/26258","id":411114919,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMTExNDkxOQ==","user":{"login":"explosivose","id":4212114,"node_id":"MDQ6VXNlcjQyMTIxMTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/4212114?v=4","gravatar_id":"","url":"https://api.github.com/users/explosivose","html_url":"https://github.com/explosivose","followers_url":"https://api.github.com/users/explosivose/followers","following_url":"https://api.github.com/users/explosivose/following{/other_user}","gists_url":"https://api.github.com/users/explosivose/gists{/gist_id}","starred_url":"https://api.github.com/users/explosivose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/explosivose/subscriptions","organizations_url":"https://api.github.com/users/explosivose/orgs","repos_url":"https://api.github.com/users/explosivose/repos","events_url":"https://api.github.com/users/explosivose/events{/privacy}","received_events_url":"https://api.github.com/users/explosivose/received_events","type":"User","site_admin":false},"created_at":"2018-08-07T16:17:34Z","updated_at":"2018-08-07T16:17:34Z","author_association":"NONE","body":"I have two different but related discriminated unions which share the set of possible type values. One union is being transformed into the other by a function, so I'd like to simply assign the type and derive the other properties in other ways"}}
{"actor":{"display_login":"explosivose"}}