{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/612","labels_url":"https://api.github.com/repos/facebook/flow/issues/612/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/612/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/612/events","html_url":"https://github.com/facebook/flow/issues/612","id":93579025,"number":612,"title":"Error reporting for Promise<A> | Promise<B> is misleading","user":{"login":"imccoy","id":95380,"avatar_url":"https://avatars.githubusercontent.com/u/95380?v=3","gravatar_id":"","url":"https://api.github.com/users/imccoy","html_url":"https://github.com/imccoy","followers_url":"https://api.github.com/users/imccoy/followers","following_url":"https://api.github.com/users/imccoy/following{/other_user}","gists_url":"https://api.github.com/users/imccoy/gists{/gist_id}","starred_url":"https://api.github.com/users/imccoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imccoy/subscriptions","organizations_url":"https://api.github.com/users/imccoy/orgs","repos_url":"https://api.github.com/users/imccoy/repos","events_url":"https://api.github.com/users/imccoy/events{/privacy}","received_events_url":"https://api.github.com/users/imccoy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/flow/labels/error%20messages","name":"error messages","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-07T17:00:13Z","updated_at":"2015-07-07T18:18:36Z","closed_at":null,"body":"When I switched our project to v0.13.1, I started seeing some new errors. It turned out that they did reflect a potential problem with our code, but the error reporting was not very helpful.\r\n\r\nWith an src/types.js like this:\r\n\r\n    /* @flow */\r\n\r\n    export type A = { a: number };\r\n    export type B = { b: string };\r\n\r\nand this src/error.js:\r\n\r\n    /* @flow */\r\n\r\n    import {A, B} from './types'\r\n\r\n    function promiseA() : Promise<A> {\r\n        return Promise.resolve({ a: 0 });\r\n    }\r\n\r\n    function promiseB() : Promise<B> {\r\n        return Promise.resolve({ b: '' });\r\n    }\r\n        \r\n    function getPromise(t) {\r\n        if (t)\r\n                return promiseA();\r\n        else\r\n                return promiseB();\r\n    }\r\n\r\n\r\n    getPromise().then(function(ab) {\r\n    });\r\n\r\nI get these errors:\r\n\r\n    /Users/iain/Code/ir/src/types.js:3:17,29: property a\r\n    Property not found in\r\n    /Users/iain/Code/ir/src/types.js:4:17,29: object type\r\n\r\n    /Users/iain/Code/ir/src/types.js:4:17,29: property b\r\n    Property not found in\r\n    /Users/iain/Code/ir/src/types.js:3:17,29: object type\r\n\r\nThe problem is that getPromise() is being inferred as `Promise<A> | Promise<B>`. Flow then tells me that A and B are insufficiently similar for this manoeuvre, but it doesn't tell me _why_ this is being attempted. In my case it was because something returned an A when a B was required, and I was lucky that the distance between error.js and types.js was pretty short."},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/119290455","html_url":"https://github.com/facebook/flow/issues/612#issuecomment-119290455","issue_url":"https://api.github.com/repos/facebook/flow/issues/612","id":119290455,"user":{"login":"imccoy","id":95380,"avatar_url":"https://avatars.githubusercontent.com/u/95380?v=3","gravatar_id":"","url":"https://api.github.com/users/imccoy","html_url":"https://github.com/imccoy","followers_url":"https://api.github.com/users/imccoy/followers","following_url":"https://api.github.com/users/imccoy/following{/other_user}","gists_url":"https://api.github.com/users/imccoy/gists{/gist_id}","starred_url":"https://api.github.com/users/imccoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imccoy/subscriptions","organizations_url":"https://api.github.com/users/imccoy/orgs","repos_url":"https://api.github.com/users/imccoy/repos","events_url":"https://api.github.com/users/imccoy/events{/privacy}","received_events_url":"https://api.github.com/users/imccoy/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T18:18:36Z","updated_at":"2015-07-07T18:18:36Z","body":"Ooh, I'll take a look at --trace.\n\nI totally understand it being tricky to get error messages right, and the\nhostility of union types in this matter :)\n\nThanks!\n\nOn Tue, 7 Jul 2015 8:10 pm Sam Goldman <notifications@github.com> wrote:\n\n> In this case, I think the error message is itself erroneous—I don't see\n> why there should be any error at all. I have marked this issue as related\n> to error messages, though. It's something we're working on, but it's a bit\n> tricky to get right, particularly with union types. If you didn't already\n> know this, you can use the --traces command line argument to get more\n> information about errors. Far from ideal, but it may help you until while\n> we incrementally improve the error messages.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/facebook/flow/issues/612#issuecomment-119288668>.\n>\n"}}