Let me illustrate a simplified example of my current code:
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);
}
}
However, I am encountering an 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 happening? I am confused about how "
'T' could be instantiated with a different subtype of constraint 'Type'
" when I have clearly extended from Base<Type.A>
. How can I resolve this issue and create specialized versions of my base class?