- Notifications
You must be signed in to change notification settings - Fork26.4k
Description
Which @angular/* package(s) are the source of the bug?
compiler-cli
Is this a regression?
No
Description
Hi guys,
While finishing up a relatively large scale migration (to functional injection with v14) instead of constructor based injection, a recurring pattern of failures required manual interventions here and there to fix up the migration failures of de-structured injectable dependencies where the schematics was effectively deleting the dependency all together such as in below example.
export class App { protected title = 'migrator-failure'; //This should be migrated to inject properly, but it fails! constructor({nativeElement}: ElementRef){ console.log(nativeElement) }}
The codebase was full of this pattern which is valid and works perfectly fine in constructor based injection context.
The expectation here would be rather something relatively as
export class App { protected title = 'migrator-failure'; nativeELement = inject(ElementRef).nativeElement; constructor(){ console.log(this.nativeElement) }}
Yet, what it produces is deleting theElementRef
all together.
export class App { protected title = 'migrator-failure'; //Emptied the constructor without proper migration/transformation to use v14 inject()! constructor(){ console.log(nativeElement) }}
While migration is effectively done after manual interventions and everything is running perfectly fine on prod, this tiny hiccup (among other one which is aliasing injectables randomly - I will try to reproduce and report separately) can be improved if you evaluate it as a valid case (which is something i believe worth having a look at) and there is room to look at it.
I have put a tiny repro repo here with separate commits to show case this (Still effectively occurs with v20).
Repo:https://github.com/bougwal/migrator-destructure-failure
Initial commit:R8-R13
post-migration result commit: R10-R17
Please provide a link to a minimal reproduction of the bug
https://github.com/bougwal/migrator-destructure-failure
Please provide the exception or error you saw
N/A
Please provide the environment you discovered this bug in (runng version
)
Details in the repo // If any more info is needed please ask below and i will provide. Yet, I think what's in the repo is sufficient to reproduce
Anything else?
PS: I didn't find an open/closed issue relevant to this, but if there is any, please let me know linking it below as dup. Many thanks !