Is it possible to create a generic class that is constrained by a union type? Consider the following scenario:
class Shoe {
constructor(public size: number){}
}
class Dress {
constructor(public style: string){}
}
class Box <T extends Shoe | Dress > {
}
Now, let's look at this example:
// since move can handle multiple boxes of either shoes or dresses
class Move<B extends Box<Shoe>[] | Box<Dress>[]> {
private stuff: B;
constructor(public toMove: Box<Shoe>[] | Box<Dress>[]) {
this.stuff = toMove // this does not compile
}
}
How can we make this work? Check out this Playground link illustrating the issue