Проблема в том, что вы ссылаетесь с public input
на typeof InputComponent
, но пытаетесь присвоить ему new InputComponent()
.
Изменение на public input: InputComponent
решает проблему.
В машинописном тексте InputComponent
относится к объекту класса, тогда как typeof InputComponent
относится к самому классу.
class InputComponent {
add():number{
return 1 + 1
}
}
class Example {
public input: InputComponent;
constructor(Input: typeof InputComponent) {
this.input = new Input();
}
}
class Example2 {
public input: InputComponent;
constructor(Input: typeof InputComponent = InputComponent) {
this.input = new Input();
}
}