Title: Inheritance for Angular decorators is not well-defined · Issue #11606 · angular/angular · GitHub
Open Graph Title: Inheritance for Angular decorators is not well-defined · Issue #11606 · angular/angular
X Title: Inheritance for Angular decorators is not well-defined · Issue #11606 · angular/angular
Description: Currently, when classes with decorators are used in an inheritance chain, the results are undefined. Consider the following two components: @Component({selector: 'a', inputs: ['metaFoo']) class A { @Input() fieldFoo; metaFoo; } @Componen...
Open Graph Description: Currently, when classes with decorators are used in an inheritance chain, the results are undefined. Consider the following two components: @Component({selector: 'a', inputs: ['metaFoo']) class A {...
X Description: Currently, when classes with decorators are used in an inheritance chain, the results are undefined. Consider the following two components: @Component({selector: 'a', inputs: ['metaFoo&...
Opengraph URL: https://github.com/angular/angular/issues/11606
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inheritance for Angular decorators is not well-defined","articleBody":"Currently, when classes with decorators are used in an inheritance chain, the results are undefined.\n\nConsider the following two components:\n\n```\n@Component({selector: 'a', inputs: ['metaFoo'])\nclass A {\n @Input() fieldFoo;\n metaFoo;\n}\n\n@Component({selector: 'b', inputs: ['metaBar']}\nclass B extends A {\n @Input() fieldBar;\n metaBar;\n}\n```\n\nCurrently, using component `B` in JIT mode does not cause an error, but only inputs `fieldBar` and `metaBar` will be understood by Angular. This is because the decorators result in properties being defined on the class functions, and those properties are subject to shadowing via prototypical inheritance. So `B.annotations` (where the `@Component` metadata lives) shadows `A.annotations`, and `B.propMetadata` (where the `@Input`s live) shadows `A.propMetadata`.\n\nIf the `@Input() fieldBar` from `B` is removed, however, then `B` will have no property metadata, and so the lookup for`B.propMetadata` will reach `A.propMetadata` via the prototype chain and suddenly the `fieldFoo` input will become visible to Angular.\n\nThere is no provision in the spec for inheritance of decorator metadata. However, Angular could be made to support well-defined rules of inheritance for its own decorators.\n\nHere is one set of rules which I believe covers most of the cases where users attempt to inherit components:\n- Class-level decorators (`@Component` and friends) have their metadata merged according to the merge rules:\n - Metadata objects are merged property by property.\n - For properties with primitive values, a subclass value, if present, overwrites a superclass value.\n - For properties with array values, the arrays are concatenated, superclass first.\n - If the subclass provides no value, the superclass value, if present, is used.\n- Property-level decorators (`@Input`, etc) on superclasses are included in compilation.\n - `@Input`s with the same name on the superclass and subclass should have the same behavior as two `@Input`s with the same name on the same class.\n\nApplying these rules would change the behavior of the above example, so component `B` would have all 4 defined inputs recognized.\n\nFor JIT mode, this requires two changes to Angular.\n\nFirst, the class-level decorators would be changed to check for metadata on the superclass, and perform the merging operation if present.\n\nSecondly, the runtime compiler would need to consider superclass metadata when checking for property annotations.\n\nFor the AOT compiler, the semantics would have to be built into the compiler itself as the decorators don't execute during AOT compilation.\n","author":{"url":"https://github.com/alxhub","@type":"Person","name":"alxhub"},"datePublished":"2016-09-14T16:10:13Z","url":"https://github.com/angular/angular/issues/11606"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e8cc39d8-28c6-a6af-2e64-dbe1c82978e2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8FC0:2AAD2E:72C551:9B27EC:6B00DC28 |
| html-safe-nonce | 1db00bc550159437090527899a165a0886f9d1b36ee19dc4f78db82a2e880423 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkMwOjJBQUQyRTo3MkM1NTE6OUIyN0VDOjZCMDBEQzI4IiwidmlzaXRvcl9pZCI6IjI1MDc4OTM0MzExODUzMDk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1599072a0af321ada631705397dc86239378d52d5790b461cc8122f42f26d033 |
| hovercard-subject-tag | issue:176950677 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/11606/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b50097f4d84b66803e15ac337c34c1346a66925cc9ccb8fe957cc45d02b5f342/angular/angular/issues/11606 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b50097f4d84b66803e15ac337c34c1346a66925cc9ccb8fe957cc45d02b5f342/angular/angular/issues/11606 |
| og:image:alt | Currently, when classes with decorators are used in an inheritance chain, the results are undefined. Consider the following two components: @Component({selector: 'a', inputs: ['metaFoo']) class A {... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alxhub |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width