有人能告诉我为什么TypeScript会说'typeof MyComponent' is not assignable to type 'Renderer'. Property 'input' is missing in type 'typeof MyComponent'
当MyComponent实现Rendered?
import { Component, Input } from '@angular/core';
interface Renderer {
input: string;
}
@Component({
selector: 'some-other-selector',
template: 'hello-mum'
})
class MyComponent implements Renderer {
@Input() input: string;
}
@Component({
selector: 'dynamic-list-app',
template: 'hello-world'
})
export class DynamicListAppComponent {
renderer: Renderer;
constructor() {
this.renderer = MyComponent;
}
}
答案 0 :(得分:2)
renderer
字段需要Renderer
类型的实例,但您要分配类MyComponent
。 typeof MyComponent
类似于java Class<MyComponent>
,它显然不是Renderer
的实例。
应为this.renderer = new MyComponent();