{"action":"created","issue":{"url":"https://api.github.com/repos/google/closure-compiler/issues/604","labels_url":"https://api.github.com/repos/google/closure-compiler/issues/604/labels{/name}","comments_url":"https://api.github.com/repos/google/closure-compiler/issues/604/comments","events_url":"https://api.github.com/repos/google/closure-compiler/issues/604/events","html_url":"https://github.com/google/closure-compiler/issues/604","id":41603663,"number":604,"title":"Feature Request: @extends for record types declarations","user":{"login":"nickgeorge","id":2492667,"avatar_url":"https://avatars.githubusercontent.com/u/2492667?v=3","gravatar_id":"","url":"https://api.github.com/users/nickgeorge","html_url":"https://github.com/nickgeorge","followers_url":"https://api.github.com/users/nickgeorge/followers","following_url":"https://api.github.com/users/nickgeorge/following{/other_user}","gists_url":"https://api.github.com/users/nickgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/nickgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickgeorge/subscriptions","organizations_url":"https://api.github.com/users/nickgeorge/orgs","repos_url":"https://api.github.com/users/nickgeorge/repos","events_url":"https://api.github.com/users/nickgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/nickgeorge/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2014-09-01T02:57:33Z","updated_at":"2015-08-11T06:34:49Z","closed_at":null,"body":"I'd really like to be able to do something like\r\n```javascript\r\n/**\r\n * @param {ShapeMessage} message Type-safe data for constructing shape.\r\n * @constructor\r\n */\r\nShape = function(message) {\r\n  this.color = message.color;\r\n};\r\n\r\n/**\r\n * @typedef {{\r\n *   color: string\r\n * }}\r\n */\r\nShapeMessage;\r\n\r\n\r\n/**\r\n * @param {SphereMessage} message Type-safe data for constructing sphere.\r\n * @constructor\r\n * @extends {Shape}\r\n */\r\nSphere = function(message) {\r\n  goog.base(this, message);\r\n  this.radius = message.radius;\r\n};\r\ngoog.inherits(Sphere, Shape)\r\n\r\n/**\r\n * @typedef {{\r\n *   radius: number\r\n * }}\r\n * @extends {ShapeMessage}\r\n */\r\nSphereMessage;\r\n\r\nnew Sphere({color: 'white', radius: 5})\r\n```\r\nSo then Sphere constructor can call goog.base to run the Shape constructor with the message safely, and then the Sphere constructor can interpret the Sphere-specific stuff itself.  This example is dopey, but you can imagine for larger trees of inheritance that this would be useful.  We create the leaf object with a fully-formed message. The message bubbles up to the base constructor, with each constructor reading the relevant parts, and type-safety guaranteed the whole way by defining a separate `type` for each constructor.\r\n\r\nI'd be totally willing to hack around on this for a bit myself if y'all think it's worth it, but thought I'd get your opinions first.\r\n\r\nThis would obviously wouldn't work if the extended `type` were a primitive, but this should be relatively easy to detect and reject. "},"comment":{"url":"https://api.github.com/repos/google/closure-compiler/issues/comments/129726435","html_url":"https://github.com/google/closure-compiler/issues/604#issuecomment-129726435","issue_url":"https://api.github.com/repos/google/closure-compiler/issues/604","id":129726435,"user":{"login":"concavelenz","id":1245994,"avatar_url":"https://avatars.githubusercontent.com/u/1245994?v=3","gravatar_id":"","url":"https://api.github.com/users/concavelenz","html_url":"https://github.com/concavelenz","followers_url":"https://api.github.com/users/concavelenz/followers","following_url":"https://api.github.com/users/concavelenz/following{/other_user}","gists_url":"https://api.github.com/users/concavelenz/gists{/gist_id}","starred_url":"https://api.github.com/users/concavelenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concavelenz/subscriptions","organizations_url":"https://api.github.com/users/concavelenz/orgs","repos_url":"https://api.github.com/users/concavelenz/repos","events_url":"https://api.github.com/users/concavelenz/events{/privacy}","received_events_url":"https://api.github.com/users/concavelenz/received_events","type":"User","site_admin":false},"created_at":"2015-08-11T06:34:49Z","updated_at":"2015-08-11T06:34:49Z","body":"There is now experimental support for @record in the compiler."}}