Title: Proposal: AOT Compiler instructions · Issue #14128 · angular/angular · GitHub
Open Graph Title: Proposal: AOT Compiler instructions · Issue #14128 · angular/angular
X Title: Proposal: AOT Compiler instructions · Issue #14128 · angular/angular
Description: [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#...
Open Graph Description: [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/angu...
X Description: [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not submit support request here, instead see https://github.co...
Opengraph URL: https://github.com/angular/angular/issues/14128
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: AOT Compiler instructions","articleBody":"```\r\n[ ] bug report => search github for a similar issue or PR before submitting\r\n[x] feature request\r\n[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n```\r\n\r\n**Current behavior**\r\nCurrently, the AOT compiler is very strict and requires every object involved in DI / metadata to resolve to a symbol that the AOT compiler can work with.\r\n\r\nIt is so strict that in some scenarios, even though the symbol information is not required, it will still fail (#12631, #13138)\r\n\r\nIt makes it difficult to write custom decorators to angular component or classes that are `@Injectable`\r\n\r\nIt is clear why all items in `providers` must resolve to a known symbol, but custom decorators for a `@Component` class can fail even though it's not important.\r\n\r\nIt also creates coupling between the compiler and the core. In general it must know about every runtime generated object even if the type is known in design time (via generic).\r\n\r\nTo solve this, the compiler workaround is to import core and register a bypass to all `core` decorators\r\n\r\n```ts\r\n this._registerDecoratorOrConstructor(this.findDeclaration(diDecorators, 'Host'), Host);\r\n this._registerDecoratorOrConstructor(\r\n this.findDeclaration(diDecorators, 'Injectable'), Injectable);\r\n this._registerDecoratorOrConstructor(this.findDeclaration(diDecorators, 'Self'), Self);\r\n```\r\n\r\nSee [code](https://github.com/angular/angular/blob/master/modules/%40angular/compiler/src/aot/static_reflector.ts#L233-L284)\r\n\r\nThis behaviour make is almost impossible to customise angular, you can customise in JIT but not in AOT. \r\nSince the compiler can not get instructions how to resolve symbols for dynamic objects the experience between JIT and AOT is different.\r\n\r\n**Expected behavior**\r\nAllow developers to provide instruction to the compiler.\r\n\r\nThe best approach would be to use **design-time decorators**, not yet supported Microsoft/TypeScript#2900\r\n\r\nThis gives the user the ability to provide design time information to the AOT compiler. \r\n\r\nUntil it lands a workaround to remove it can be using a webpack loader either via [Transformers API](https://github.com/Microsoft/TypeScript/pull/11561) or through a simple loader that removes that code in 2 places.\r\n\r\nA great use case is mixins. Now that Microsoft/TypeScript#13604 is in master, and will be in 2.2 this is really important for implementing the mixin pattern.\r\n\r\n```ts\r\nclass User_ {\r\n}\r\n\r\nexport const User = RestMixin(User);\r\nexport type User = User_ & Mixin\r\n```\r\n\r\nCurrently, this will fail if `User` is included as a provider. \r\nThere is no actual reason for it to fail since `RestMixin` returns all the type information. \r\nIt fails because the compiler can't resolve `User` into a symbol since it is dealing with complex function (RestMixin)\r\n\r\nIf I could notify the compiler what to do no compilation error.\r\nIn this case telling the compiler to resolve the symbol of `User_` to `User`\r\n\r\nIn the current code I tried it via this hack, it worked:\r\n\r\n```\r\nif (staticSymbol.name === 'RestMixin') converter = (ctx, args) => { return args[0]};\r\n```\r\n\r\n\r\n@mhevery @tbosch ","author":{"url":"https://github.com/shlomiassaf","@type":"Person","name":"shlomiassaf"},"datePublished":"2017-01-26T23:35:09Z","url":"https://github.com/angular/angular/issues/14128"}
| 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:d875d6f2-d7f7-7f65-0f2c-8bcfe9793b6d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E5E:1AE20C:3FFEEC:529A17:6B00D419 |
| html-safe-nonce | 22ae99a5b07d468dc1f8dc4a9e7f206f6ac5c6c21aaba659976229a08a28a6aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTVFOjFBRTIwQzozRkZFRUM6NTI5QTE3OjZCMDBENDE5IiwidmlzaXRvcl9pZCI6IjI1NDIwNzM0MTkyNDQwMzMwNDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9737b2ea043742b6742e141ee721dff50cb6e062959885bc6f5ec35c87f83d58 |
| hovercard-subject-tag | issue:203521095 |
| 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/14128/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d34a129e6b066bb4e30a061c2640d10305c794c7848cf4d8f4f2ca8aac6a68fa/angular/angular/issues/14128 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d34a129e6b066bb4e30a061c2640d10305c794c7848cf4d8f4f2ca8aac6a68fa/angular/angular/issues/14128 |
| og:image:alt | [ ] bug report => search github for a similar issue or PR before submitting [x] feature request [ ] support request => Please do not submit support request here, instead see https://github.com/angu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shlomiassaf |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5 |
| 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 | 4943239a6d2c591325dad6e5c313e1cafda877f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width