{"action":"opened","issue":{"url":"https://api.github.com/repos/angular/clutz/issues/331","repository_url":"https://api.github.com/repos/angular/clutz","labels_url":"https://api.github.com/repos/angular/clutz/issues/331/labels{/name}","comments_url":"https://api.github.com/repos/angular/clutz/issues/331/comments","events_url":"https://api.github.com/repos/angular/clutz/issues/331/events","html_url":"https://github.com/angular/clutz/issues/331","id":172832794,"number":331,"title":"handle closures' type transformation expressions","user":{"login":"rkirov","id":95713,"avatar_url":"https://avatars.githubusercontent.com/u/95713?v=3","gravatar_id":"","url":"https://api.github.com/users/rkirov","html_url":"https://github.com/rkirov","followers_url":"https://api.github.com/users/rkirov/followers","following_url":"https://api.github.com/users/rkirov/following{/other_user}","gists_url":"https://api.github.com/users/rkirov/gists{/gist_id}","starred_url":"https://api.github.com/users/rkirov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkirov/subscriptions","organizations_url":"https://api.github.com/users/rkirov/orgs","repos_url":"https://api.github.com/users/rkirov/repos","events_url":"https://api.github.com/users/rkirov/events{/privacy}","received_events_url":"https://api.github.com/users/rkirov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-23T23:40:50Z","updated_at":"2016-08-23T23:40:50Z","closed_at":null,"body":"Closure supports type macros, for example for typing out Promise:\r\n\r\n```js\r\n/**\r\n * @constructor\r\n * @template T\r\n */\r\nangular.$q.Promise = function() {};\r\n\r\n/**\r\n * Apply Type Transformation Language to allow more accurate templated type\r\n * definition.\r\n * This is copied from <code>goog.Thenable.prototype.then</code>, with the only\r\n * difference being the raw type as angular.$q.Promise instead of goog.Promise.\r\n *\r\n * @param {?(function(this:THIS, T): VALUE)=} opt_onFulfilled\r\n * @param {?(function(?): ?)=} opt_onRejected\r\n * @param {?(function(?): ?)=} opt_notifyCallback\r\n * @return {RESULT}\r\n * @template THIS\r\n * @template VALUE\r\n * @template RESULT := type('angular.$q.Promise',\r\n *     cond(isUnknown(VALUE), unknown(),\r\n *       mapunion(VALUE, (V) =>\r\n *         cond(isTemplatized(V) && sub(rawTypeOf(V), 'IThenable'),\r\n *           templateTypeOf(V, 0),\r\n *           cond(sub(V, 'angular.$q.Promise'),\r\n *              unknown(),\r\n *              V)))))\r\n *  =:\r\n */\r\nangular.$q.Promise.prototype.then =\r\n    function(opt_onFulfilled, opt_onRejected, opt_notifyCallback) {};\r\n```\r\n\r\nCurrently, clutz doesn't choke on this, but produces a not very usable type:\r\n\r\n```ts\r\n    then < THIS , VALUE , RESULT > (opt_onFulfilled ? : ( (a : T ) => VALUE ) | null , opt_onRejected ? : ( (a : any ) => any ) | null , opt_notifyCallback ? : ( (a : any ) => any ) | null ) : RESULT ;\r\n  }\r\n```\r\nSince the dependency on `VALUE` and `RESULT` is lost, it is always the empty object type `{}`. Thus a promise of this type is unusable after `promise.then(x => x)`.\r\n\r\nThis feature is not heavily used, so even a first order approximation say using `VALUE` instead of  `RESULT` will make the generated promise types a lot more useful. It will be missing the Promise unwrapping feature, but that is not as common simply returning the result type."}}
{"actor":{"display_login":"rkirov"}}