Have you ever wondered if it's possible to achieve something similar to this in TypeScript?
If not, is there a documented reason explaining why the compiler struggles with inferring nested type parameters?
Let me provide an illustrative example of what I'm aiming for:
interface TestFilter {
name?: string;
}
interface FilterComponent<F> {
setFilter(filter: F)
}
class TestFilterComponent implements FilterComponent<TestFilter> {
private filter: TestFilter;
setFilter(filter: TestFilter) {
this.filter = filter;
}
}
// Is there a way to utilize F without establishing it as a distinct type parameter?
// For instance: class FilterWrapperComponent<FC extends FilterComponent<F>>
abstract class FilterWrapperComponent<F, FC extends FilterComponent<F>> {
private sidebarFilter: FC;
private modalFilter: FC;
public passFilter(filter: F) {
this.sidebarFilter.setFilter(filter);
this.modalFilter.setFilter(filter);
}
}
// All I want is to directly specify "extends FilterWrapperComponent<TestFilterComponent>"
// and have TestFilter automatically assigned to F
class TestFilterWrapperComponent extends FilterWrapperComponent<TestFilter, TestFilterComponent> {
}
You can also experiment with this code snippet on the TypeScript playground.