Struggling to expand an abstract generic class and encountering issues with extending certain methods.
Take a look at this:
abstract class A<T,K> {
protected abstract upload<S>(item: T): S
protected abstract download(item: T): K
}
class B<T, K > extends A<T, K>{
protected upload(item: T):string {
return 'hello'
}
protected download(item: T): number{
return 1
}
}
The error message when extending the upload
method in class B
is:
Property 'upload' in type 'B<T, K>' cannot be assigned to the same property in base type 'A<T, K>'.
Type '(item: T) => string' cannot be assigned to type '<S>(item: T) => S'.
Type 'string' cannot be assigned to type 'S'.
when extending the download
method in class B
:
Property 'download' in type 'B<T, K>' cannot be assigned to the same property in base type 'A<T, K>'.
Type '(item: T) => number' cannot be assigned to type '(item: T) => K'.
Type 'number' cannot be assigned to type 'K'.
'number' can be assigned to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint '{}'.