How can I condition the generic return type when a value is not present?
type Foo = {};
class Bar<P extends Foo> {
static make<P extends Foo>(a?: P): Bar<P> {
return new Bar();
}
}
Bar.make() // returns Bar<Foo>
However, I would like to achieve something like this:
class Bar<P extends Foo> {
static make<P extends Foo>(a?: P): Bar<P extends undefined ? never : Foo> {
return new Bar();
}
}
Bar.make() // returns Bar<never>
Bar.make({}) // returns Bar<Foo>