{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3812","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3812/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3812/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3812/events","html_url":"https://github.com/Microsoft/TypeScript/issues/3812","id":94344571,"number":3812,"title":"Support type guards on property access expression","user":{"login":"tinganho","id":1324476,"avatar_url":"https://avatars.githubusercontent.com/u/1324476?v=3","gravatar_id":"","url":"https://api.github.com/users/tinganho","html_url":"https://github.com/tinganho","followers_url":"https://api.github.com/users/tinganho/followers","following_url":"https://api.github.com/users/tinganho/following{/other_user}","gists_url":"https://api.github.com/users/tinganho/gists{/gist_id}","starred_url":"https://api.github.com/users/tinganho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tinganho/subscriptions","organizations_url":"https://api.github.com/users/tinganho/orgs","repos_url":"https://api.github.com/users/tinganho/repos","events_url":"https://api.github.com/users/tinganho/events{/privacy}","received_events_url":"https://api.github.com/users/tinganho/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Committed","name":"Committed","color":"009800"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"closed","locked":false,"assignee":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/1","html_url":"https://github.com/Microsoft/TypeScript/milestones/TypeScript%202.0","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/1/labels","id":721040,"number":1,"title":"TypeScript 2.0","description":"The next major release of TypeScript","creator":{"login":"RyanCavanaugh","id":6685088,"avatar_url":"https://avatars.githubusercontent.com/u/6685088?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanCavanaugh","html_url":"https://github.com/RyanCavanaugh","followers_url":"https://api.github.com/users/RyanCavanaugh/followers","following_url":"https://api.github.com/users/RyanCavanaugh/following{/other_user}","gists_url":"https://api.github.com/users/RyanCavanaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanCavanaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanCavanaugh/subscriptions","organizations_url":"https://api.github.com/users/RyanCavanaugh/orgs","repos_url":"https://api.github.com/users/RyanCavanaugh/repos","events_url":"https://api.github.com/users/RyanCavanaugh/events{/privacy}","received_events_url":"https://api.github.com/users/RyanCavanaugh/received_events","type":"User","site_admin":false},"open_issues":132,"closed_issues":151,"state":"open","created_at":"2014-07-14T23:24:03Z","updated_at":"2016-04-11T13:18:52Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2015-07-10T16:46:19Z","updated_at":"2016-04-11T13:18:52Z","closed_at":"2016-04-11T13:18:52Z","body":"I just found out that property access expressions doesn't work on type predicate functions and `instanceof` type guards.\r\n\r\n```typescript\r\n\r\nclass A {\r\n    propA: number;\r\n}\r\n\r\nclass B {\r\n    propB: number;\r\n}\r\nclass C {\r\n    propC: A;\r\n}\r\n\r\ndeclare function isA(p1: any): p1 is D;\r\n\r\ninterface D {\r\n    a: A | B\r\n    b: A | C;\r\n}\r\n\r\nlet d: D;\r\nif (isA(d.b)) {\r\n    d.b.propA; //error\r\n}\r\n\r\nfunction foo(d: D) {\r\n    if (d.b instanceof A) {\r\n        d.b.propA // error\r\n    }\r\n}\r\n```\r\n\r\nI'm not sure if there is an easy fix on this problem. We are provided just a symbol when narrowing. That symbol represent the left most expression and then we walk up the if statement. There is no easy way of controlling symbol by symbol on each namespace in a property access expression in the if-statement-body. Because there is no info about the property access expression provided in `getTypeOfSymbolAtLocation(symbol: Symbol, node: Node)`.\r\n\r\nI also found that type assertion expressions are also not working in type predicate functions. But I will land a fix on that.\r\n\r\n```typescript\r\nif (isA(<A>union)) {\r\n    a = union;\r\n}\r\nif (isA(union as A)) {\r\n    a = union;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/208337937","html_url":"https://github.com/Microsoft/TypeScript/issues/3812#issuecomment-208337937","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3812","id":208337937,"user":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"created_at":"2016-04-11T13:18:52Z","updated_at":"2016-04-11T13:18:52Z","body":"Closed in #7140."}}