Let's say we have this example:
class Base<T extends Base<T>> {}
class ClassA extends Base<ClassA> {}
class ClassB extends Base<ClassB> {}
type Condition = ClassA extends ClassB ? true : false;
The base class has one generic argument which basically says, anything derivind from it should template it with it's own type.
Then we have 2 classes that derive from said base.
Lastly I've created a conditional type that checks whether the derived classes extend each other.
To my surprise typescript is telling me that they do, but I think that this condition should be false. ClassA
isn't extending ClassB
and vice versa. Only ClassA extends Base<ClassA>
should return true.
Is this an issue in typescript's conditional types or am I missing something? I came across this issue while building more complex conditional type, that as well was returning unexpected results.
Edit: The generic arguments aren't needed as well. Even this example returns wrong result:
class Base {}
class ClassA extends Base {}
class ClassB extends Base {}
type Condition = ClassA extends ClassB ? true : false;