Preview:```ts
abstract class SomeParent {
abstract someFunc<C extends SomeParent>(): Promise<C>
}
class SomeChild implements SomeParent {
async someFunc() {
return new SomeChild()
}
}```
5 messages · Page 1 of 1 (latest)
Preview:```ts
abstract class SomeParent {
abstract someFunc<C extends SomeParent>(): Promise<C>
}
class SomeChild implements SomeParent {
async someFunc() {
return new SomeChild()
}
}```
I'm not sure I explained this well, but essentially I can't seem to return 'SomeChild()' from my implementation of 'someFunc' because of an error I haven't seen before:
Property 'someFunc' in type 'SomeChild' is not assignable to the same property in base type 'SomeParent'.
Type '() => Promise<SomeChild>' is not assignable to type '<C extends SomeParent>() => Promise<C>'.
Type 'Promise<SomeChild>' is not assignable to type 'Promise<C>'.
Type 'SomeChild' is not assignable to type 'C'.
'C' could be instantiated with an arbitrary type which could be unrelated to 'SomeChild'.(2416)
SomeParent's someFunc is a function with generic parameters whereas SomeChild's someFunc has no generic parameters
and you don't need generic parameters to achieve what you want, just write Promise<SomeParent>
Argh you genius! Not using generics fixed everything.