Please, consider the following code:
class Wrapper<T> {
public static forConstructor<S extends Object>(construc: { new (...args: any[]): S }): Wrapper<S> {
return new Wrapper<S>();
}
}
class A {
private aaa: string = null;
}
class B {
private bbb: string = null;
}
const wrapper: Wrapper<A> = Wrapper.forConstructor(B);// LINE X
At LINE X Wrapper<A> = Wrapper<B> that is an wrong, however, TypeScript doesn't show error at this line. What is my mistake?
Wrapper<A>andWrapper<B>are structurally compatible. If you'll store the passed constructor as a field (for example) you'll get an error