Cannot assign an abstract constructor type to a non-abstract constructor type

Viewed 2247

I'm trying to make an abstract component in angular but am getting following error:

Error: src/app/app.module.ts:191:5 - error TS2322: Type 'typeof AbstractFormComponent' is not assignable to type 'any[] | Type<any>'.
  Type 'typeof AbstractFormComponent' is not assignable to type 'Type<any>'.
    Cannot assign an abstract constructor type to a non-abstract constructor type.

191     AbstractFormComponent
        ~~~~~~~~~~~~~~~~~~~~~

This is my abstract Component:

@Component({
  selector: 'app-abstract-form',
  templateUrl: './abstract-form.component.html',
  styleUrls: ['./abstract-form.component.scss']
})
export abstract class AbstractFormComponent implements OnInit, AfterViewInit {

  protected constructor(protected formService: FormService) {
  }

  protected abstract getForms(): AbstractControl[];

  ngOnInit(): void {
  }

  ngAfterViewInit(): void {
    this.getForms().forEach(f => this.formService.addForm(f));
  }
}

It seems like Angular has problems with the constructor but I need the constructor for the service so I cannot delete it. Is there any way that I can use abstract classes with a constructor/injecting services?

2 Answers

Solution is just not adding the abstract component to app.modules. I can still use it as abstract Component and I don't get any errors.

Related