I come from a background in C# and I'm currently trying to get my head around Typescript. I've run in to the following issue while creating a generic abtract class in Typescript, and I'm not sure if it's a problem with my implementation, or a limitation of the language:
Given the following abstract class, and class extending it:
abstract class Filter<T> {
value T;
abstract apply<T>(items: T[]): T[];
}
class StringFilter extends Filter<string> {
apply(items: string[]) {
return items.filter(i => this.value === i);
}
}
I get the following error:
Property 'apply' in type 'StringFilter' is not assignable to the same property in base type 'Filter<string>'.
Type '(items: string[]) => string[]' is not assignable to type '<T>(items: T[]) => T[]'.
In C# I would have expected the apply method to share the same generic type as the class, but in Typescript this doesn't seem to be the case.
How can I make sure that a type of Filter<string> has an apply method of type (items: string[]) => string[]?