How do I make typeof BaseListComponent below assignable?
The code below throws the following error:
Type '
({ title: string; component: typeof QuestionsListComponent; } | { title: string; component: ...'is not assignable to type'{ title: string; component: typeof BaseListComponent; }[]'.
Excerpt:
abstract class BaseListComponent {
protected title
}
class WeatherListComponent extends BaseListComponent {}
class QuestionsListComponent extends BaseListComponent {}
let containerItems: Array<{title: string, component: typeof BaseListComponent}>;
containerItems = [
{title:'TypeScript', component: QuestionsListComponent},
{title:'Angular2', component: QuestionsListComponent},
{title:'Weather', component: WeatherListComponent}
]
P.S this is a simplified excerpt from an angular application and so there is logic behind this madness.
Using angular's Type interface was the solution. A better explanation of what Type is can be found here. Steps to solve:
Import Type like so: import { Type } from "@angular/core";
Replace typeof BaseListComponent with Type<BaseListComponent>
For people coming here who are not using angular, this thread might be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With