Example:
class A {}
class B extends A {
constructor(a: number) {
super();
a.toFixed();
}
}
const a: Class<B> = B;
const b: Class<A> = a;
const x = new b(); // no error
This looks like a bug in that the constructor of B shouldn't be permitted (it is incompatible with A's constructor).
Consider an example with a normal method and you can see that Flow correctly errors:
class A {
foo() {}
}
class B extends A {
foo(a: number) {}
}
Overall, Class<> should be covariant because static-classes in JS themselves are an "instance" of the static-class they extend.
It is very common in OOP languages to change constructor in subclasses arbitrarily (e.g. provide default args), so it will be very inconvenient.
Another option is not to consider class B subtype of class A if constructor B is not a subtype of constructor of A.
Another option is not to consider class B subtype of class A if constructor B is not a subtype of constructor of A.
I like this approach
Most helpful comment
I like this approach