{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8383","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8383/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8383/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8383/events","html_url":"https://github.com/Microsoft/TypeScript/issues/8383","id":151948433,"number":8383,"title":"control flow with instanceof not works properly","user":{"login":"dashaus","id":1870208,"avatar_url":"https://avatars.githubusercontent.com/u/1870208?v=3","gravatar_id":"","url":"https://api.github.com/users/dashaus","html_url":"https://github.com/dashaus","followers_url":"https://api.github.com/users/dashaus/followers","following_url":"https://api.github.com/users/dashaus/following{/other_user}","gists_url":"https://api.github.com/users/dashaus/gists{/gist_id}","starred_url":"https://api.github.com/users/dashaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dashaus/subscriptions","organizations_url":"https://api.github.com/users/dashaus/orgs","repos_url":"https://api.github.com/users/dashaus/repos","events_url":"https://api.github.com/users/dashaus/events{/privacy}","received_events_url":"https://api.github.com/users/dashaus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-29T19:15:56Z","updated_at":"2016-04-29T19:43:59Z","closed_at":null,"body":"<!--\r\nThank you for contributing to TypeScript! Please review this checklist\r\n       before submitting your issue.\r\n[ ] Many common issues and suggestions are addressed in the FAQ\r\n     https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n[ ] Search for duplicates before logging new issues\r\n    https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue\r\n[ ] Questions are best asked and answered at Stack Overflow\r\n    http://stackoverflow.com/questions/tagged/typescript\r\n\r\nFor bug reports, please include the information below.\r\n__________________________________________________________ -->\r\n\r\n**TypeScript Version:** \r\n\r\nnightly (1.9.0-dev.20160429)\r\n\r\n**Code**\r\n\r\n```ts\r\nclass AAA {\r\n    fieldA: string;\r\n}\r\n\r\nclass BBB {\r\n    fieldB: string;\r\n}\r\n\r\nclass AA {\r\n    data: AAA;\r\n}\r\n\r\nclass BB {\r\n    data: BBB;\r\n}\r\n\r\nclass A {\r\n    d: AA;\r\n}\r\n\r\nclass B {\r\n    d: BB;\r\n}\r\n\r\nfunction main(x: A | B) {\r\n    for (let i of [1, 1]) {\r\n        if (x instanceof A) {\r\n            x.d.data.fieldA;\r\n        } else if (x instanceof B) {\r\n            x.d.data.fieldB; // Not compiles here. \r\n        }\r\n    }\r\n}\r\n\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nTo access to the `fieldB` field of `BBB` class inside of block `} else if (x instanceof B) {`\r\n\r\n**Actual behavior:** \r\n\r\nThe compiler raises the follow error: `TS2339: Property 'fieldB' does not exist on type 'AAA'.`. \r\nThe behavior in the version 1.8.10 is correct.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/215859112","html_url":"https://github.com/Microsoft/TypeScript/issues/8383#issuecomment-215859112","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8383","id":215859112,"user":{"login":"malibuzios","id":17719551,"avatar_url":"https://avatars.githubusercontent.com/u/17719551?v=3","gravatar_id":"","url":"https://api.github.com/users/malibuzios","html_url":"https://github.com/malibuzios","followers_url":"https://api.github.com/users/malibuzios/followers","following_url":"https://api.github.com/users/malibuzios/following{/other_user}","gists_url":"https://api.github.com/users/malibuzios/gists{/gist_id}","starred_url":"https://api.github.com/users/malibuzios/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malibuzios/subscriptions","organizations_url":"https://api.github.com/users/malibuzios/orgs","repos_url":"https://api.github.com/users/malibuzios/repos","events_url":"https://api.github.com/users/malibuzios/events{/privacy}","received_events_url":"https://api.github.com/users/malibuzios/received_events","type":"User","site_admin":false},"created_at":"2016-04-29T19:43:58Z","updated_at":"2016-04-29T19:43:58Z","body":"I tried to reduce the example to the simplest one possible, that still errored:\r\n\r\n```ts\r\nclass A {\r\n    prop: { a: string };\r\n}\r\n\r\nclass B {\r\n    prop: { b: string; }\r\n}\r\n\r\ndeclare let x: A | B;\r\n\r\nwhile (true) {\r\n\tif (x instanceof A) {\r\n\t\tx.prop.a;\r\n\t} else if (x instanceof B) {\r\n\t\tx.prop.b; // property 'b' doesn't exist on type { a: string }\r\n\t}\r\n}\r\n```\r\nIf the `while` enclosure is removed the error doesn't occur (same with `for`, I only used `while` for simplicity)."}}