{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/2509","repository_url":"https://api.github.com/repos/facebook/flow","labels_url":"https://api.github.com/repos/facebook/flow/issues/2509/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/2509/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/2509/events","html_url":"https://github.com/facebook/flow/issues/2509","id":178480567,"number":2509,"title":"Flow doesn't refine type when using a reference of `Array.isArray`","user":{"login":"HeavenVolkoff","id":9082460,"avatar_url":"https://avatars.githubusercontent.com/u/9082460?v=3","gravatar_id":"","url":"https://api.github.com/users/HeavenVolkoff","html_url":"https://github.com/HeavenVolkoff","followers_url":"https://api.github.com/users/HeavenVolkoff/followers","following_url":"https://api.github.com/users/HeavenVolkoff/following{/other_user}","gists_url":"https://api.github.com/users/HeavenVolkoff/gists{/gist_id}","starred_url":"https://api.github.com/users/HeavenVolkoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HeavenVolkoff/subscriptions","organizations_url":"https://api.github.com/users/HeavenVolkoff/orgs","repos_url":"https://api.github.com/users/HeavenVolkoff/repos","events_url":"https://api.github.com/users/HeavenVolkoff/events{/privacy}","received_events_url":"https://api.github.com/users/HeavenVolkoff/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-21T22:44:14Z","updated_at":"2016-10-17T22:18:32Z","closed_at":"2016-09-26T05:20:32Z","body":"Example:\r\n\r\n```javascript\r\nlet isArray = Array.isArray\r\n\r\nfunction f (arr: Array<mixed>): Array<mixed> {\r\n  let subArr:mixed = []\r\n  \r\n  if (isArray(subArr)) {\r\n    return subArr\r\n  }\r\n  \r\n  return []\r\n}\r\n```\r\n\r\nFlow result:\r\n```\r\n7:     return subArr\r\n              ^ mixed. This type is incompatible with the expected return type of\r\n3: function f (arr: Array<mixed>): Array<mixed> {\r\n                                   ^ array type\r\n```\r\n\r\nHowever, it refines just fine in the following code:\r\n```javascript\r\nfunction f (arr: Array<mixed>): Array<mixed> {\r\n  let subArr:mixed = []\r\n  \r\n  if (Array.isArray(subArr)) {\r\n    return subArr\r\n  }\r\n  \r\n  return []\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/254351434","html_url":"https://github.com/facebook/flow/issues/2509#issuecomment-254351434","issue_url":"https://api.github.com/repos/facebook/flow/issues/2509","id":254351434,"user":{"login":"vkurchatkin","id":2993861,"avatar_url":"https://avatars.githubusercontent.com/u/2993861?v=3","gravatar_id":"","url":"https://api.github.com/users/vkurchatkin","html_url":"https://github.com/vkurchatkin","followers_url":"https://api.github.com/users/vkurchatkin/followers","following_url":"https://api.github.com/users/vkurchatkin/following{/other_user}","gists_url":"https://api.github.com/users/vkurchatkin/gists{/gist_id}","starred_url":"https://api.github.com/users/vkurchatkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkurchatkin/subscriptions","organizations_url":"https://api.github.com/users/vkurchatkin/orgs","repos_url":"https://api.github.com/users/vkurchatkin/repos","events_url":"https://api.github.com/users/vkurchatkin/events{/privacy}","received_events_url":"https://api.github.com/users/vkurchatkin/received_events","type":"User","site_admin":false},"created_at":"2016-10-17T22:18:32Z","updated_at":"2016-10-17T22:18:32Z","body":"@HeavenVolkoff can you reopen this? Predicates are already merged, but this is still a problem. Another example of incorrect behaviour:\r\n\r\n```js\r\nconst Array = {\r\n  isArray: () => true\r\n};\r\n\r\nfunction test(x: null | Array<mixed>) {\r\n  if (Array.isArray(x)) {\r\n     x.forEach(() => {}); \r\n  }\r\n}\r\n```"}}
{"actor":{"display_login":"vkurchatkin"}}