{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/1595","repository_url":"https://api.github.com/repos/facebook/flow","labels_url":"https://api.github.com/repos/facebook/flow/issues/1595/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/1595/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/1595/events","html_url":"https://github.com/facebook/flow/issues/1595","id":144583162,"number":1595,"title":"x.constructor type refinement","user":{"login":"maxxk","id":1191859,"avatar_url":"https://avatars.githubusercontent.com/u/1191859?v=3","gravatar_id":"","url":"https://api.github.com/users/maxxk","html_url":"https://github.com/maxxk","followers_url":"https://api.github.com/users/maxxk/followers","following_url":"https://api.github.com/users/maxxk/following{/other_user}","gists_url":"https://api.github.com/users/maxxk/gists{/gist_id}","starred_url":"https://api.github.com/users/maxxk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxxk/subscriptions","organizations_url":"https://api.github.com/users/maxxk/orgs","repos_url":"https://api.github.com/users/maxxk/repos","events_url":"https://api.github.com/users/maxxk/events{/privacy}","received_events_url":"https://api.github.com/users/maxxk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-30T13:08:35Z","updated_at":"2016-03-30T13:59:05Z","closed_at":null,"body":"Is it possible to enable type refinement for the dynamic type tests based on the constructor equality?\r\nThe following examples show two use cases for which flow v0.22.1 reports the same error.\r\n\r\n```javascript\r\n/*@flow */\r\n\r\ntype StringOrBool = string | boolean\r\n\r\nfunction length_if(x : StringOrBool) : number {\r\n  if (x.constructor == String) {\r\n    return x.length;\r\n  }\r\n  if (x.constructor == Boolean) {\r\n    return 0;\r\n  }\r\n  throw new Error('Unreachable')\r\n}\r\n\r\nfunction length_switch(x : StringOrBool ) : number {\r\n  switch (x.constructor) {\r\n    case String:\r\n      return x.length;\r\n    case Boolean:\r\n      return 0;\r\n  }\r\n  throw new Error('Unreachable')\r\n}\r\n```\r\n\r\n```\r\nsrc/flow-switch-constructor.js:7\r\n  7:     return x.length;\r\n                  ^^^^^^ property `length`. Property not found in\r\n  3: type StringOrBool = string | boolean\r\n                                  ^^^^^^^ Boolean\r\n\r\nsrc/flow-switch-constructor.js:18\r\n 18:       return x.length;\r\n                    ^^^^^^ property `length`. Property not found in\r\n 18:       return x.length;\r\n                  ^ Boolean\r\n```"},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/203445326","html_url":"https://github.com/facebook/flow/issues/1595#issuecomment-203445326","issue_url":"https://api.github.com/repos/facebook/flow/issues/1595","id":203445326,"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-03-30T13:59:05Z","updated_at":"2016-03-30T13:59:05Z","body":"The problem is with `setPrototypeOf`, not with tagged unions. I guess if your type is `string | boolean`, then it would be a valid assertion, nut not if there is an object type in the union."}}