Conversation
The following provider:
```ts
{
provide: APP_INITIALIZER,
useFactory: (initService: InitService) => {
return () => initService.init()
},
deps: [InitService],
multi: true
}
```
was migrated into:
```ts
provideAppInitializer(() => { return ((initService: InitService) => {
return () => initService.init()
})(inject(InitService)); })
```
This doesn't compile because there is an extra function:
```
✘ [ERROR] TS2345: Argument of type '() => () => void' is not assignable to parameter of type '() => void | Observable<unknown> | Promise<unknown>'.
Type '() => void' is not assignable to type 'void | Observable<unknown> | Promise<unknown>'. [plugin angular-compiler]
src/app/app.config.ts:7:26:
7 │ ...ovideAppInitializer(() => { return ((initService: InitService) => {
```
It now migrates the provider into:
```ts
provideAppInitializer(((initService: InitService) => {
return () => initService.init()
})(inject(InitService)))
```
|
cc. @yjaaidi |
|
Nice catch @cexbrayat ! Thanks for the fix |
|
This PR was merged into the repository by commit a116a64. The changes were merged into the following branches: main, 19.0.x |
…8493) The following provider: ```ts { provide: APP_INITIALIZER, useFactory: (initService: InitService) => { return () => initService.init() }, deps: [InitService], multi: true } ``` was migrated into: ```ts provideAppInitializer(() => { return ((initService: InitService) => { return () => initService.init() })(inject(InitService)); }) ``` This doesn't compile because there is an extra function: ``` ✘ [ERROR] TS2345: Argument of type '() => () => void' is not assignable to parameter of type '() => void | Observable<unknown> | Promise<unknown>'. Type '() => void' is not assignable to type 'void | Observable<unknown> | Promise<unknown>'. [plugin angular-compiler] src/app/app.config.ts:7:26: 7 │ ...ovideAppInitializer(() => { return ((initService: InitService) => { ``` It now migrates the provider into: ```ts provideAppInitializer(((initService: InitService) => { return () => initService.init() })(inject(InitService))) ``` PR Close #58493
|
Oh! Sorry! I'm afk and still didn't get a chance to look at this closely. I'm afraid that this isn't the right fix. It's hard to read on my phone but it looks like the inject is not running in an injection context. The function initially returned in the outer arrow function should have been called but still inside the outer arrow: provideAppInitializer(() => { return ((initService: InitService) => {
return () => initService.init()
})(inject(InitService))(); })
// ^ |
|
I just submitted a fix that should also improve readability. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The following provider:
was migrated in:
This doesn't compile because there is an extra function:
What is the new behavior?
It now migrates the provider in:
Does this PR introduce a breaking change?
Other information