无法将抽象构造函数类型分配给非抽象构造函数类型

Pur*_*ang 9 abstract-class typescript angular

我试图以角度制作一个抽象组件,但出现以下错误:

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
        ~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

这是我的抽象组件:

@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));
  }
}
Run Code Online (Sandbox Code Playgroud)

Angular 的构造函数似乎有问题,但我需要该服务的构造函数,所以我无法删除它。有什么方法可以将抽象类与构造函数/注入服务一起使用?

Pur*_*ang 13

解决方案只是不将抽象组件添加到 app.modules 中。我仍然可以将它用作抽象组件,并且不会收到任何错误。