I have a class that takes a generic:
abstract class Base<P extends SomeType = SomeType> {
// ...
}
And a class that extends it:
class A extends Base<SomeTypeA> {
// ...
}
Its hard to describe, but basically I’m wondering if its possible with typescript to know "What is the type that class A extended Base with?"
Something like
type PropType = ExtendedGeneric<A> // SomeTypeA
>Solution :
You can use a conditional type to extract the type that was passed to Base
type ExtendedGeneric<T extends Base<any>> = T extends Base<infer P> ? P: never
type PropType = ExtendedGeneric<A> // SomeTypeA
You can read more about conditional types here