Allow `inject()` usage as constructor parameter properties default
### 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 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: ```ts MyCmp.ctorParameters = () => [ { type: MyService } ]; ``` Cf. https://github.com/angular/angular/blob/3a60063a54d850c50ce962a8a39ce01cfee71398/packages/compiler-cli/src/transformers/downlevel_decorators_transform/downlevel_decorators_transform.ts The problem with this approach is that it slows down community initiatives of integrating Angular with other tools. e.g. Vite, Vitest, SWC... This 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 ## `inject()` to the rescue The good news is that an app using only `inject()` instead of constructor param types to retrieve dependencies will not need this transformer: ```ts class MyCmp { myService = inject(MyService); } ``` The 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 resolutio
Posted by yjaaidi on Oct 3, 2022, 8:15 AM
Tags
Related issues
- Many devs love to shit on the guy from the 'I just want the exe.
- Now imagine how poor people stress if their smartphone bricks or gets damaged or lost.
- Resuming an extended-thinking session fails permanently with 400 "thinking blocks cannot be modified" (transcript stores thinking text as empty but keeps signat
- I'll preface this with a statement that as a European I want European alternatives to succeed, and MS-owned GitHub to shrivel and disappear.
- Yeah, but there’s a world of difference between “not perfect” and “we rounded a few sliders, and now the modal is a nightmare to use”.
- I used to write a lot of native Windows corporate software in the 90's and 2000's and my standard login window was a floating draggable o...
Raise real-world problems, find people facing the same issue, and discuss solutions.2,500 issues0 comments
reliability (SaaS)
Many devs love to shit on the guy from the 'I just want the exe.
Now imagine how poor people stress if their smartphone bricks or gets damaged or lost.
Resuming an extended-thinking session fails permanently with 400 "thinking blocks cannot be modified" (transcript stores thinking text as empty but keeps signat
I'll preface this with a statement that as a European I want European alternatives to succeed, and MS-owned GitHub to shrivel and disappear.
Yeah, but there’s a world of difference between “not perfect” and “we rounded a few sliders, and now the modal is a nightmare to use”.
I used to write a lot of native Windows corporate software in the 90's and 2000's and my standard login window was a floating draggable o...
App broken with Mosquitto broker 7.0.0
[BUG] Remote Control: automatic reconnection doesn't work -- connection drops silently with no recovery
Allow `inject()` usage as constructor parameter properties default
### 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 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: ```ts MyCmp.ctorParameters = () => [ { type: MyService } ]; ``` Cf. https://github.com/angular/angular/blob/3a60063a54d850c50ce962a8a39ce01cfee71398/packages/compiler-cli/src/transformers/downlevel_decorators_transform/downlevel_decorators_transform.ts The problem with this approach is that it slows down community initiatives of integrating Angular with other tools. e.g. Vite, Vitest, SWC... This 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 ## `inject()` to the rescue The good news is that an app using only `inject()` instead of constructor param types to retrieve dependencies will not need this transformer: ```ts class MyCmp { myService = inject(MyService); } ``` The 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 resolutio
Comments (0)
No comments yet. Start the discussion.