How can I define a function which is an implementation of a type declaration that includes generics?
Here's what I mean:
abstract class Base {}
class Sub extends Base {}
declare type BaseFactory = <T extends Base>() => T;
let subFactory: BaseFactory = <Sub>():Sub => new Sub();
console.debug(subFactory()); // expect instance of Sub
Unfortunately, this produces the following error:
Sub is not assignable to parameter of type Base
Can this be done?
/edit nevermind, it actually works in Playground. Guess it's a compiler version issue