Here's a simplified example of what I'm doing:
enum Type {A, B}
class Base<T extends Type> {
constructor(public type: T) {}
static create<T extends Type>(type: T): Base<T> {
return new Base(type);
}
}
class A extends Base<Type.A> {
static override create(): A {
return super.create(Type.A);
}
}
But I'm getting this error:
Class static side 'typeof A' incorrectly extends base class static side 'typeof Base'.
The types returned by 'create(...)' are incompatible between these types.
Type 'A' is not assignable to type 'Base<T>'.
Type 'Type.A' is not assignable to type 'T'.
'Type.A' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Type'. ts(2417)
Why is this? I don't understand how "'T' could be instantiated with a different subtype of constraint 'Type'" when I've explicitly extended from Base<Type.A>. How do I work around this to create specializations of my base class?