{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/30445128","id":30445128,"diff_hunk":"@@ -438,6 +525,46 @@ module ts {\n         }\r\n     }\r\n \r\n+    export function forEachYieldExpression(body: Block, visitor: (expr: YieldExpression) => void): void {\r","path":"src/compiler/utilities.ts","position":98,"original_position":98,"commit_id":"7e798e904aa3b51b7dfb1e0a12c5103e206ef573","original_commit_id":"7e798e904aa3b51b7dfb1e0a12c5103e206ef573","user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"body":"`visitor` returns void and so does `forEachYieldExpression`. If we're doing this, maybe we should instead also change `forEachReturnStatement`, but the reason I wrote that the way I did is to stay true to the behavior of the general family of functions.","created_at":"2015-05-15T20:52:09Z","updated_at":"2015-05-15T20:52:09Z","html_url":"https://github.com/Microsoft/TypeScript/pull/3031#discussion_r30445128","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/30445128"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/3031#discussion_r30445128"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031","id":34689115,"html_url":"https://github.com/Microsoft/TypeScript/pull/3031","diff_url":"https://github.com/Microsoft/TypeScript/pull/3031.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/3031.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3031","number":3031,"state":"open","locked":false,"title":"Basic support for generators as iterators","user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"body":"This covers part of the proposal in https://github.com/Microsoft/TypeScript/issues/2873. Namely, it handles checking types in a generator function, and inferring the return type of a generator function.\r\n\r\nSpecifically, here is what is implemented (copied from the proposal, with strikethroughs marking the differences):\r\n\r\n## Type annotation on a generator\r\nA generator function can have a return type annotation, just like a function. The annotation represents the type of the generator returned by the function. Here is an example:\r\n```ts\r\nfunction *g(): Iterable<string> {\r\n    for (var i = 0; i < 100; i++) {\r\n        yield \"\"; // string is assignable to string\r\n    }\r\n    yield * otherStringGenerator(); // otherStringGenerator must be iterable and element type assignable to string\r\n}\r\n```\r\nHere are the rules:\r\n\r\n* ~~`IterableIterator<any>` must be assignable to the type annotation.~~\r\n    * An element type T is structurally retrieved from the type denoted by the type annotation, considering the type annotation as an IterableIterator. It is an error if `IterableIterator<T>` for this T is not assignable to the type denoted by the type annotation.\r\n* The operand of every yield expression (if present) must be assignable to the element type of the generator (string in this case)\r\n* The operand of every `yield *` expression must be assignable to `Iterable<any>`\r\n* The element type of the operand of every `yield *` expression must be assignable to the element type of the generator. (string is assignable to string)\r\n* The operand of a `yield` (if present) expression is contextually typed by the element type of the generator (string)\r\n* The operand of a `yield *` expression is contextually typed by the type of the generator (`Iterable<string>`)\r\n* A `yield` expression has type any.\r\n* A `yield *` expression has type any.\r\n* ~~The generator cannot have return expressions.~~\r\n    * The generator is allowed to have return expressions as well, but they are ignored for the purposes of type checking the generator type.\r\n\r\n## Inferring the type of a generator\r\nA generator function with no type annotation can have the type annotation inferred. So in the following case, the type will be inferred from the yield statements:\r\n```ts\r\nfunction *g() {\r\n    for (var i = 0; i < 100; i++) {\r\n        yield \"\"; // infer string\r\n    }\r\n    yield * otherStringGenerator(); // infer element type of otherStringGenerator\r\n}\r\n```\r\n* Rather than inferring Iterable, we will infer IterableIterator, with some element type. The reason is that someone can call next directly on the generator without first getting its iterator. A generator is in fact an iterator as well as an iterable.\r\n* The element type is the common supertype of all the yield operands and the element types of all the `yield *` operands.\r\n* It is an error if there is no common supertype.\r\n* As before, the operand of every `yield *` expression must be assignable to `Iterable<any>`\r\n* `yield` and `yield *` expressions again have type any\r\n* If the generator is contextually typed, the operands of `yield` expressions are contextually typed by the element type of the contextual type\r\n* If the generator is contextually typed, the operands of `yield *` expressions are contextually typed by the contextual type.\r\n* Again, return expressions are allowed, but not used for inferring the element type.~~ Return expressions are not allowed. Consider relaxing this later, particularly if there is no type annotation.~~\r\n* If there are no yield operands and no `yield*` expressions, the element type is an implicit any, which errors in noImplicitAny mode.\r\n","created_at":"2015-05-05T00:47:19Z","updated_at":"2015-05-15T20:52:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"27bb503033f76ebb0b644f5d249e6fae120d7173","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3031/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/7e798e904aa3b51b7dfb1e0a12c5103e206ef573","head":{"label":"Microsoft:generators","ref":"generators","sha":"7e798e904aa3b51b7dfb1e0a12c5103e206ef573","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-05-15T20:45:06Z","pushed_at":"2015-05-15T18:22:45Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":773384,"stargazers_count":5183,"watchers_count":5183,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":542,"mirror_url":null,"open_issues_count":623,"forks":542,"open_issues":623,"watchers":5183,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"f8c10ff1154dba9f3558d1990ca6fb35977c10ec","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-05-15T20:45:06Z","pushed_at":"2015-05-15T18:22:45Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":773384,"stargazers_count":5183,"watchers_count":5183,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":542,"mirror_url":null,"open_issues_count":623,"forks":542,"open_issues":623,"watchers":5183,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/3031"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/3031"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/3031/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3031/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/7e798e904aa3b51b7dfb1e0a12c5103e206ef573"}}}}