Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error after running the inject migration #443

Closed
timdeschryver opened this issue Jul 6, 2024 · 0 comments · Fixed by #444
Closed

Compile error after running the inject migration #443

timdeschryver opened this issue Jul 6, 2024 · 0 comments · Fixed by #444

Comments

@timdeschryver
Copy link
Contributor

The inject migration only updates the first usage when a property get's assigned in the ctor.
See the below snippets for an example.

Input:

    import { Component } from '@angular/core';

    @Component({
      template: ''
    })
    export class MyComponent {
      depOne$: Observable<string>;
      depTwo$: Observable<string>;
      depThree$: Observable<string>;
      depFour$: Observable<string>;

      constructor(private service: Service) {
        this.depOne$ = service.depOne$;
        this.depTwo$ = service.depTwo$;
        this.depThree$ = this.service.depThree$;
        this.depFour$ = service.depFour$;
      }
    }

Expected output:

    import { Component, inject } from '@angular/core';

    @Component({
      template: ''
    })
    export class MyComponent {
      private service = inject(Service);
      depOne$: Observable<string>;
      depTwo$: Observable<string>;
      depThree$: Observable<string>;
      depFour$: Observable<string>;

      constructor() {
        this.depOne$ = this.service.depOne$;
        this.depTwo$ = this.service.depTwo$;
        this.depThree$ = this.service.depThree$;
        this.depFour$ = this.service.depFour$;
      }
    }

Received output:

    import { Component, inject } from '@angular/core';

    @Component({
      template: ''
    })
    export class MyComponent {
      private service = inject(Service);
      depOne$: Observable<string>;
      depTwo$: Observable<string>;
      depThree$: Observable<string>;
      depFour$: Observable<string>;

      constructor() {
        this.depOne$ = this.service.depOne$;
        this.depTwo$ = service.depTwo$;
                       ~~~~~~~ throws error, migration doesn't add this keyword
        this.depThree$ = this.service.depThree$;
        this.depFour$ = service.depFour$;
                       ~~~~~~~ throws error, migration doesn't add this keyword
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant