GitHub PullRequestReviewCommentEvent at 2014-12-09 22:11:37
Repository: TypeScript
Actor: JsonFreeman
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/21567206","id":21567206,"diff_hunk":"@@ -1679,11 +1682,67 @@ module ts {\n             return classType.typeParameters ? createTypeReference(<GenericType>classType, map(classType.typeParameters, _ => anyType)) : classType;\r\n         }\r\n \r\n-        function getTypeOfVariableOrParameterOrPropertyDeclaration(declaration: VariableOrParameterOrPropertyDeclaration): Type {\r\n+        // Return the type of the given property in the given type, or undefined if no such property exists\r\n+        function getTypeOfPropertyOfType(type: Type, name: string): Type {\r\n+            var prop = getPropertyOfType(type, name);\r\n+            return prop ? getTypeOfSymbol(prop) : undefined;\r\n+        }\r\n+\r\n+        // Return the inferred type for a binding element\r\n+        function getTypeForBindingElement(declaration: BindingElement): Type {\r\n+            var pattern = <BindingPattern>declaration.parent;\r\n+            var parentType = getTypeForVariableLikeDeclaration(<VariableLikeDeclaration>pattern.parent);\r\n+            // If parent has the unknown (error) type, then so does this binding element\r\n+            if (parentType === unknownType) {\r\n+                return unknownType;\r\n+            }\r\n+            // If no type was specified or inferred for parent, or if the specified or inferred type is any,\r\n+            // infer from the initializer of the binding element if one is present. Otherwise, go with the\r\n+            // undefined or any type of the parent.\r\n+            if (!parentType || parentType === anyType) {\r","path":"src/compiler/checker.ts","position":162,"original_position":162,"commit_id":"7bc35b3ae0e663e59b8305433da17508b868f140","original_commit_id":"7bc35b3ae0e663e59b8305433da17508b868f140","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":"Do we do that for contextual typing? An analogous example (courtesy of @CyrusNajmabadi):\r\n\r\n```ts\r\nvar v: (a: any) => void = (a = 1) { a.blah };\r\n```\r\n\r\nShould `a` in the body be of type any or number? Applying the reasoning you stated from destructuring, it seems like in this example it should be number, not any.","created_at":"2014-12-09T22:11:37Z","updated_at":"2014-12-09T22:11:37Z","html_url":"https://github.com/Microsoft/TypeScript/pull/1346#discussion_r21567206","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/21567206"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/1346#discussion_r21567206"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346","id":25388939,"html_url":"https://github.com/Microsoft/TypeScript/pull/1346","diff_url":"https://github.com/Microsoft/TypeScript/pull/1346.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/1346.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1346","number":1346,"state":"closed","locked":false,"title":"Destructuring","user":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"body":"This pull request adds support for ECMAScript 6 destructuring declarations and assignments with down-level ES3 and ES5 code generation. For example:\r\n```typescript\r\nvar [x, y] = [10, 20];\r\n[x, y] = [y, x];\r\n```\r\nThe above example generates:\r\n```javascript\r\nvar _a = [10, 20], x = _a[0], y = _a[1];\r\n_b = [y, x], x = _b[0], y = _b[1];\r\n```\r\nAnother example:\r\n```typescript\r\ninterface NameAndLocation {\r\n    name: string;\r\n    location: [number, number];\r\n}\r\n\r\nfunction getNameAndLocation(): NameAndLocation {\r\n    return { name: \"top-left\", location: [10, 20] };\r\n}\r\n\r\nfunction displayNameAndLocation({name, location: [x, y] = [0, 0]}: NameAndLocation) {\r\n    console.log(\"name=\" + name + \" x=\" + x + \" y=\" + y);\r\n}\r\n\r\nvar {name, location: [x, y]} = getNameAndLocation();\r\ndisplayNameAndLocation(getNameAndLocation());\r\n```\r\nThe above example generates:\r\n```javascript\r\nfunction getNameAndLocation() {\r\n    return { name: \"top-left\", location: [10, 20] };\r\n}\r\nfunction displayNameAndLocation(_a) {\r\n    var name = _a.name, _b = _a.location, _c = _b === void 0 ? [0, 0] : _b, x = _c[0], y = _c[1];\r\n    console.log(\"name=\" + name + \" x=\" + x + \" y=\" + y);\r\n}\r\nvar _a = getNameAndLocation(), name = _a.name, _b = _a.location, x = _b[0], y = _b[1];\r\ndisplayNameAndLocation(getNameAndLocation());\r\n```\r\nWork still remaining:\r\n* Support for rest elements in array destructuring.\r\n* Pure ES6 code generation with no rewriting (under -target ES6 switch).\r\n* Updated spec.\r\n","created_at":"2014-12-03T01:11:37Z","updated_at":"2014-12-09T22:11:37Z","closed_at":"2014-12-09T19:39:23Z","merged_at":"2014-12-09T19:39:23Z","merge_commit_sha":"1ff0a236f91f34e48be23b7414e264bb86aaa707","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1346/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/7bc35b3ae0e663e59b8305433da17508b868f140","head":{"label":"Microsoft:destructuring","ref":"destructuring","sha":"7bc35b3ae0e663e59b8305433da17508b868f140","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":"2014-12-09T20:52:56Z","pushed_at":"2014-12-09T21:37:47Z","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":400503,"stargazers_count":3010,"watchers_count":3010,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":253,"mirror_url":null,"open_issues_count":337,"forks":253,"open_issues":337,"watchers":3010,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"ecfed18d4c5e5330cfd4f7bdc12a8dc98a498bfe","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":"2014-12-09T20:52:56Z","pushed_at":"2014-12-09T21:37:47Z","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":400503,"stargazers_count":3010,"watchers_count":3010,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":253,"mirror_url":null,"open_issues_count":337,"forks":253,"open_issues":337,"watchers":3010,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/1346"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/1346"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/1346/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1346/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/7bc35b3ae0e663e59b8305433da17508b868f140"}}}}