René's URL Explorer Experiment


Title: Allow `inject()` usage as constructor parameter properties default · Issue #47606 · angular/angular · GitHub

Open Graph Title: Allow `inject()` usage as constructor parameter properties default · Issue #47606 · angular/angular

X Title: Allow `inject()` usage as constructor parameter properties default · Issue #47606 · angular/angular

Description: Which @angular/* package(s) are relevant/related to the feature request? compiler-cli, compiler Description Transformer in the way Injectables' dependencies are currently guessed by analyzing the constructor parameter types. This typing ...

Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? compiler-cli, compiler Description Transformer in the way Injectables' dependencies are currently guessed by analyzing the c...

X Description: Which @angular/* package(s) are relevant/related to the feature request? compiler-cli, compiler Description Transformer in the way Injectables' dependencies are currently guessed by analyzing t...

Opengraph URL: https://github.com/angular/angular/issues/47606

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow `inject()` usage as constructor parameter properties default","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncompiler-cli, compiler\n\n### Description\n\n## Transformer in the way\r\n\r\nInjectables' dependencies are currently guessed by analyzing the constructor parameter types.\r\nThis typing information is lost after transforming TypeScript to ECMAScript. In order to fix this, the compiler has to run a transformer that converts this information into something like:\r\n```ts\r\nMyCmp.ctorParameters = () => [\r\n   { type: MyService }\r\n];\r\n```\r\nCf. https://github.com/angular/angular/blob/3a60063a54d850c50ce962a8a39ce01cfee71398/packages/compiler-cli/src/transformers/downlevel_decorators_transform/downlevel_decorators_transform.ts\r\n\r\nThe problem with this approach is that it slows down community initiatives of integrating Angular with other tools. e.g. Vite, Vitest, SWC...\r\nThis forces tools to hack their way through. For instance, jest-preset-angular downloads the internal CLI transformer: https://github.com/thymikee/jest-preset-angular/blob/f24156ea1f7532c02c44d8d023b54623a4bccccd/scripts/prebuild.js#L9\r\n\r\n## `inject()` to the rescue\r\n\r\nThe good news is that an app using only `inject()` instead of constructor param types to retrieve dependencies will not need this transformer:\r\n```ts\r\nclass MyCmp {\r\n myService = inject(MyService);\r\n}\r\n```\r\n\r\nThe problem with using `inject()` function this way is that it doesn't allow injecting dependencies manually. This means that all tests will need the `TestBed` or similar to control dependencies resolution.\r\nTo allow manual instantiation, the current alternative would be something **non-explicit, verbose and error-prone** like this:\r\n\r\n```ts\r\nclass MyCmp {\r\n   // let's not do this\r\n  constructor(myService?: MyService) {\r\n    this.myService = myService ?? inject(MyService);\r\n  }\r\n}\r\n```\n\n### Proposed solution\n\nCompiler should bypass type-based dependency injection when a default value is set and the given type can't be resolved.\r\nThis would allow the following syntax which currently works if this transformer is disabled:\r\n\r\n```ts\r\nclass MyCmp {\r\n  constructor(private myService = inject(MyService)) {}\r\n}\r\n```\r\n\r\nThis has the following advantages:\r\n- ✨ constructor parameters transformer is not needed anymore... so easier integration with existing tools\r\n- ✨ manual instantiation is still possible\r\n- ✨ all the benefits of `inject`: type-inference, consistent way of injecting class-based & injection-token based deps: `locale = inject(LOCALE_ID)`, controlling options (e.g. optional, self) through flags instead of decorators.\n\n### Alternatives considered\n\nUse `inject()` and never instantiate manually.","author":{"url":"https://github.com/yjaaidi","@type":"Person","name":"yjaaidi"},"datePublished":"2022-10-03T08:15:35Z","url":"https://github.com/angular/angular/issues/47606"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0a22b3b8-73bd-304b-7c7c-5bb359e0ac13
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id96A8:334404:D6A271:11E49F3:6AED426D
html-safe-nonce84b3ae46348bb3df06b57fc65179f78dfbd325836c1dd6522f5bc053f4877731
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkE4OjMzNDQwNDpENkEyNzE6MTFFNDlGMzo2QUVENDI2RCIsInZpc2l0b3JfaWQiOiI0OTA1Mzk2MDIzMDIzNDUyNzgxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac06f5162f0924964276deb1337c359a3c41a7dedecd2a65ac36d814f96f253ee4
hovercard-subject-tagissue:1394328946
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/47606/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4faa5f30301254ecc6b8e0dcd9a97152ec3b4ef4c4d95a62e09ac11e0c1e917e/angular/angular/issues/47606
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4faa5f30301254ecc6b8e0dcd9a97152ec3b4ef4c4d95a62e09ac11e0c1e917e/angular/angular/issues/47606
og:image:altWhich @angular/* package(s) are relevant/related to the feature request? compiler-cli, compiler Description Transformer in the way Injectables' dependencies are currently guessed by analyzing the c...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameyjaaidi
hostnamegithub.com
expected-hostnamegithub.com
None56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/47606#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F47606
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F47606
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/47606
Reloadhttps://github.com/angular/angular/issues/47606
Reloadhttps://github.com/angular/angular/issues/47606
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues847 (847)https://github.com/angular/angular/issues
Pull requests178 (178)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality39 (39)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/pulse
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/47606
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/47606
Allow inject() usage as constructor parameter properties defaulthttps://github.com/angular/angular/issues/47606#top
https://github.com/alxhub
P2The issue is important to a large percentage of users, with a workaroundhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P2%22
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: dihttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20di%22
Backloghttps://github.com/angular/angular/milestone/82
https://github.com/yjaaidi
yjaaidihttps://github.com/yjaaidi
on Oct 3, 2022https://github.com/angular/angular/issues/47606#issue-1394328946
https://github.com/angular/angular/blob/3a60063a54d850c50ce962a8a39ce01cfee71398/packages/compiler-cli/src/transformers/downlevel_decorators_transform/downlevel_decorators_transform.tshttps://github.com/angular/angular/blob/3a60063a54d850c50ce962a8a39ce01cfee71398/packages/compiler-cli/src/transformers/downlevel_decorators_transform/downlevel_decorators_transform.ts
https://github.com/thymikee/jest-preset-angular/blob/f24156ea1f7532c02c44d8d023b54623a4bccccd/scripts/prebuild.js#L9https://github.com/thymikee/jest-preset-angular/blob/f24156ea1f7532c02c44d8d023b54623a4bccccd/scripts/prebuild.js#L9
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: dihttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20di%22
on Oct 3, 2022https://github.com/angular/angular/issues/47606#event-7505576813
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on Oct 3, 2022https://github.com/angular/angular/issues/47606#event-7505576971
https://github.com/santoshyadavdev
santoshyadavdevhttps://github.com/santoshyadavdev
on Oct 3, 2022https://github.com/angular/angular/issues/47606#issuecomment-1265988463
https://github.com/yjaaidi
yjaaidihttps://github.com/yjaaidi
on Oct 4, 2022https://github.com/angular/angular/issues/47606#issuecomment-1266469995
https://github.com/SanderElias
SanderEliashttps://github.com/SanderElias
on Oct 4, 2022https://github.com/angular/angular/issues/47606#issuecomment-1266489580
@yjaaidihttps://github.com/yjaaidi
https://github.com/yjaaidi
yjaaidihttps://github.com/yjaaidi
on Oct 4, 2022https://github.com/angular/angular/issues/47606#issuecomment-1266942194
@SanderEliashttps://github.com/SanderElias
https://marmicode.io/blog/angular-inject-and-injection-functionshttps://marmicode.io/blog/angular-inject-and-injection-functions
https://marmicode.io/blog/angular-private-serviceshttps://marmicode.io/blog/angular-private-services
https://fastapi.tiangolo.com/tutorial/dependencies/https://fastapi.tiangolo.com/tutorial/dependencies/
https://github.com/yjaaidi
yjaaidihttps://github.com/yjaaidi
on Oct 4, 2022https://github.com/angular/angular/issues/47606#issuecomment-1266946172
https://github.com/SanderElias
SanderEliashttps://github.com/SanderElias
on Oct 11, 2022https://github.com/angular/angular/issues/47606#issuecomment-1274318517
@yjaaidihttps://github.com/yjaaidi
https://github.com/yjaaidi
yjaaidihttps://github.com/yjaaidi
on Oct 12, 2022https://github.com/angular/angular/issues/47606#issuecomment-1275653829
@SanderEliashttps://github.com/SanderElias
@yjaaidihttps://github.com/yjaaidi
alxhubhttps://github.com/alxhub
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgenthttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P3%22
on Nov 16, 2022https://github.com/angular/angular/issues/47606#event-7825679263
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
Backloghttps://github.com/angular/angular/milestone/82
on Nov 16, 2022https://github.com/angular/angular/issues/47606#event-7825679596
alxhubhttps://github.com/alxhub
P2The issue is important to a large percentage of users, with a workaroundhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P2%22
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgenthttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P3%22
on Jan 6, 2023https://github.com/angular/angular/issues/47606#event-8165097503
alxhubhttps://github.com/alxhub
on Jan 6, 2023https://github.com/angular/angular/issues/47606#event-8165097530
https://github.com/hiepxanh
hiepxanhhttps://github.com/hiepxanh
on Dec 12, 2023https://github.com/angular/angular/issues/47606#issuecomment-1851598573
angular/angular-cli#26323https://github.com/angular/angular-cli/issues/26323
https://github.com/JeanMeche
JeanMechehttps://github.com/JeanMeche
on Nov 1, 2026https://github.com/angular/angular/issues/47606#issuecomment-6563700801
JeanMechehttps://github.com/JeanMeche
not plannedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Nov 1, 2026https://github.com/angular/angular/issues/47606#event-34853582757
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/47606
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/47606
alxhubhttps://github.com/alxhub
P2The issue is important to a large percentage of users, with a workaroundhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P2%22
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: dihttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20di%22
BacklogNo due datehttps://github.com/angular/angular/milestone/82
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.