I have following code:
class Factory<K, T extends new (...p: any) => any> {
add(key: K, fn: (...p: ConstructorParameters<T>) => InstanceType<T>) {
}
}
class Foo {
constructor(a: number) {
}
}
class Boo {
constructor(a: number) {
}
}
new Factory<number, typeof Foo>().add(1, (a) => new Boo(a))
I would assume that this should fail to compile as Boo
is not derived from Foo
. But it works fine.
Am I missing something?