{"action":"created","issue":{"url":"https://api.github.com/repos/angular/clutz/issues/802","repository_url":"https://api.github.com/repos/angular/clutz","labels_url":"https://api.github.com/repos/angular/clutz/issues/802/labels{/name}","comments_url":"https://api.github.com/repos/angular/clutz/issues/802/comments","events_url":"https://api.github.com/repos/angular/clutz/issues/802/events","html_url":"https://github.com/angular/clutz/pull/802","id":386901733,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM1NTEyNTI2","number":802,"title":"Improve this type","user":{"login":"teppeis","id":26476,"node_id":"MDQ6VXNlcjI2NDc2","avatar_url":"https://avatars0.githubusercontent.com/u/26476?v=4","gravatar_id":"","url":"https://api.github.com/users/teppeis","html_url":"https://github.com/teppeis","followers_url":"https://api.github.com/users/teppeis/followers","following_url":"https://api.github.com/users/teppeis/following{/other_user}","gists_url":"https://api.github.com/users/teppeis/gists{/gist_id}","starred_url":"https://api.github.com/users/teppeis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teppeis/subscriptions","organizations_url":"https://api.github.com/users/teppeis/orgs","repos_url":"https://api.github.com/users/teppeis/repos","events_url":"https://api.github.com/users/teppeis/events{/privacy}","received_events_url":"https://api.github.com/users/teppeis/received_events","type":"User","site_admin":false},"labels":[{"id":190745377,"node_id":"MDU6TGFiZWwxOTA3NDUzNzc=","url":"https://api.github.com/repos/angular/clutz/labels/cla:%20yes","name":"cla: yes","color":"207de5","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-03T16:35:52Z","updated_at":"2018-12-05T00:02:57Z","closed_at":"2018-12-04T17:05:23Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/angular/clutz/pulls/802","html_url":"https://github.com/angular/clutz/pull/802","diff_url":"https://github.com/angular/clutz/pull/802.diff","patch_url":"https://github.com/angular/clutz/pull/802.patch"},"body":"fixes #709 \r\n\r\n## New features\r\n\r\nAdditionally, these forms are supported:\r\n\r\n```js\r\n/**\r\n * @return {!GenericClass<T>}\r\n * @this {T}\r\n * @template T\r\n */\r\nA.prototype.foo = function() {\r\n  return new GenericClass(this);\r\n};\r\n\r\n/**\r\n * @return {!Array<T>}\r\n * @this {T}\r\n * @template T\r\n */\r\nA.prototype.array = function() {\r\n  return [this];\r\n};\r\n\r\n/**\r\n * @return {!Object<string, T>}\r\n * @this {T}\r\n * @template T\r\n */\r\nA.prototype.object = function() {\r\n  return {foo: this};\r\n};\r\n\r\n/**\r\n * @return {{foo: T}}\r\n * @this {T}\r\n * @template T\r\n */\r\nA.prototype.record = function() {\r\n  return {foo: this};\r\n};\r\n\r\n\r\n/**\r\n * @param {string} str\r\n * @this {Function}\r\n */\r\nA.func = function(str) {\r\n};\r\n```\r\n\r\nare converted to\r\n\r\n```ts\r\n  class A {\r\n    array < T > (this : T ) : T [] ;\r\n    foo < T > (this : T ) : GenericClass < T > ;\r\n    object < T > (this : T ) : { [ key: string ]: T } ;\r\n    record < T > (this : T ) : { foo : T } ;\r\n    func (this : Function , str : string ) : void ;\r\n  }\r\n```\r\n\r\nBut non-templatized `this` in a function type is not supported yet.\r\n```js\r\n/**\r\n * @type {function(this: Date)}\r\n */\r\nvar foo = function() {};\r\n```\r\n\r\n## Changes\r\n\r\n```js\r\n/**\r\n * @return {THIS}\r\n * @this {THIS}\r\n * @template THIS\r\n */\r\nC.prototype.foo = function() {\r\n  return this;\r\n};\r\n```\r\nis currently converted to \r\n```ts\r\n  class C {\r\n    foo ( ) : this ;\r\n  }\r\n```\r\nbut in this PR, it is converted to\r\n```ts\r\n  class C {\r\n    foo < THIS > (this : THIS ) : THIS ;\r\n  }\r\n```\r\n\r\nBecause polymorphic `this` types are invalid in some places, but templatized `this` is all valid. They are equivalent. For simplicity, I convert all to templatized `this`.\r\n\r\n```ts\r\ndeclare namespace ಠ_ಠ.clutz.nsThis {\r\n  class A {\r\n    // all valid\r\n    returnThis<T>(this: T): T;\r\n    array<T>(this: T): T[];\r\n    generics<T>(this: T): Set<T>;\r\n    object<T>(this: T) : { [ key: string ]: T } ;\r\n    record<T>(this: T): { foo: T };\r\n  }\r\n  class B {\r\n    returnThis(): this; // valid\r\n    generics(): Set<this>;  // valid\r\n    array(): this[]; // valid\r\n    object(): { [ key: string ]: this } ; // invalid!!!\r\n    record(): { foo: this }; // invalid!!!\r\n  }\r\n}\r\n```\r\n[playground](http://www.typescriptlang.org/play/#src=declare%20namespace%20%E0%B2%A0_%E0%B2%A0.clutz.nsThis%20%7B%0D%0A%20%20class%20A%20%7B%0D%0A%20%20%20%20returnThis%3CT%3E(this%3A%20T)%3A%20T%3B%0D%0A%20%20%20%20array%3CT%3E(this%3A%20T)%3A%20T%5B%5D%3B%0D%0A%20%20%20%20generics%3CT%3E(this%3A%20T)%3A%20Set%3CT%3E%3B%0D%0A%20%20%20%20object%3CT%3E(this%3A%20T)%20%3A%20%7B%20%5B%20key%3A%20string%20%5D%3A%20T%20%7D%20%3B%0D%0A%20%20%20%20record%3CT%3E(this%3A%20T)%3A%20%7B%20foo%3A%20T%20%7D%3B%0D%0A%20%20%7D%0D%0A%20%20class%20B%20%7B%0D%0A%20%20%20%20returnThis()%3A%20this%3B%0D%0A%20%20%20%20generics()%3A%20Set%3Cthis%3E%3B%0D%0A%20%20%20%20array()%3A%20this%5B%5D%3B%0D%0A%20%20%20%20object()%3A%20%7B%20%5B%20key%3A%20string%20%5D%3A%20this%20%7D%20%3B%0D%0A%20%20%20%20record()%3A%20%7B%20foo%3A%20this%20%7D%3B%0D%0A%20%20%7D%0D%0A%7D)\r\n"},"comment":{"url":"https://api.github.com/repos/angular/clutz/issues/comments/444306605","html_url":"https://github.com/angular/clutz/pull/802#issuecomment-444306605","issue_url":"https://api.github.com/repos/angular/clutz/issues/802","id":444306605,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDMwNjYwNQ==","user":{"login":"teppeis","id":26476,"node_id":"MDQ6VXNlcjI2NDc2","avatar_url":"https://avatars0.githubusercontent.com/u/26476?v=4","gravatar_id":"","url":"https://api.github.com/users/teppeis","html_url":"https://github.com/teppeis","followers_url":"https://api.github.com/users/teppeis/followers","following_url":"https://api.github.com/users/teppeis/following{/other_user}","gists_url":"https://api.github.com/users/teppeis/gists{/gist_id}","starred_url":"https://api.github.com/users/teppeis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teppeis/subscriptions","organizations_url":"https://api.github.com/users/teppeis/orgs","repos_url":"https://api.github.com/users/teppeis/repos","events_url":"https://api.github.com/users/teppeis/events{/privacy}","received_events_url":"https://api.github.com/users/teppeis/received_events","type":"User","site_admin":false},"created_at":"2018-12-05T00:02:57Z","updated_at":"2018-12-05T00:02:57Z","author_association":"CONTRIBUTOR","body":"@mprobst thanks!"}}
{"actor":{"display_login":"teppeis"}}