{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/834","labels_url":"https://api.github.com/repos/facebook/flow/issues/834/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/834/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/834/events","html_url":"https://github.com/facebook/flow/issues/834","id":107466397,"number":834,"title":"yielding promise in generator","user":{"login":"GGAlanSmithee","id":11805103,"avatar_url":"https://avatars.githubusercontent.com/u/11805103?v=3","gravatar_id":"","url":"https://api.github.com/users/GGAlanSmithee","html_url":"https://github.com/GGAlanSmithee","followers_url":"https://api.github.com/users/GGAlanSmithee/followers","following_url":"https://api.github.com/users/GGAlanSmithee/following{/other_user}","gists_url":"https://api.github.com/users/GGAlanSmithee/gists{/gist_id}","starred_url":"https://api.github.com/users/GGAlanSmithee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GGAlanSmithee/subscriptions","organizations_url":"https://api.github.com/users/GGAlanSmithee/orgs","repos_url":"https://api.github.com/users/GGAlanSmithee/repos","events_url":"https://api.github.com/users/GGAlanSmithee/events{/privacy}","received_events_url":"https://api.github.com/users/GGAlanSmithee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-21T08:37:55Z","updated_at":"2015-09-21T12:17:07Z","closed_at":null,"body":"I am using `generators` as a placeholder to ES7 `async` as described in [this article](http://davidwalsh.name/async-generators). The idea is to `yield` a promise to get the actual value returned, instead of the promise.\r\n\r\nHowever, I am unable to get `flow` to work with this pattern. The value being returned from `yield` is always treated as `undefined`. I am unsure if this is a bug or if I am using it in a wrong way.\r\n\r\nI have created a [repo](https://github.com/GGAlanSmithee/flowgenerator) with an example of the problem. Running `flow` on the code in the `src` folder will give the error. "},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/141954285","html_url":"https://github.com/facebook/flow/issues/834#issuecomment-141954285","issue_url":"https://api.github.com/repos/facebook/flow/issues/834","id":141954285,"user":{"login":"samwgoldman","id":254842,"avatar_url":"https://avatars.githubusercontent.com/u/254842?v=3","gravatar_id":"","url":"https://api.github.com/users/samwgoldman","html_url":"https://github.com/samwgoldman","followers_url":"https://api.github.com/users/samwgoldman/followers","following_url":"https://api.github.com/users/samwgoldman/following{/other_user}","gists_url":"https://api.github.com/users/samwgoldman/gists{/gist_id}","starred_url":"https://api.github.com/users/samwgoldman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samwgoldman/subscriptions","organizations_url":"https://api.github.com/users/samwgoldman/orgs","repos_url":"https://api.github.com/users/samwgoldman/repos","events_url":"https://api.github.com/users/samwgoldman/events{/privacy}","received_events_url":"https://api.github.com/users/samwgoldman/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T12:17:07Z","updated_at":"2015-09-21T12:17:07Z","body":"So, this is somewhat unfortunate, but is intentional and is a consequence of the nature of generators.\r\n\r\nAny value yielded to the generator is wrapped in a [maybe type](http://flowtype.org/docs/nullable-types.html), because the argument to `next` is optional.\r\n\r\nWhat flow is saying to you in that error is that `res` *may* be undefined. You need to \"unwrap\" the maybe type to get at the underlying string. You can do that using [dynamic type tests](http://flowtype.org/docs/dynamic-type-tests.html).\r\n\r\nSo, something like `if (res == null) { /* error handling */ } else { /* normal case */ }`.\r\n\r\nAlso, Flow has special knowledge of an `invariant` function, so if you want to ignore error handling, you can add a line like `invariant(res != null, \"debug message\")` and flow will consider `res` to be non-null/non-undefined for the rest of that function. There is an invariant package on npm."}}