title: How to write generics for factories using psalm and phpstan
body: <p>I'm trying out phpstan and psalm for php and I would like to write a class that can take different type of objects and return the right one based on the factory to call.</p>
  <p>What I'm trying to achieve is that if I pass an object of type A to the Transformer, the compiler knows that a SuperA will be returned.</p>
  <p>While I can go without errors in psalm (though I still get SuperA|SuperB instead of the right object), I got an error on what I'm passing in phpstan.</p>
  <p><a href="https://phpstan.org/r/4fce6f46-7aea-4f73-8259-df895910f064" rel="nofollow noreferrer">https://phpstan.org/r/4fce6f46-7aea-4f73-8259-df895910f064</a></p>
  <p><a href="https://psalm.dev/r/352e64ea95" rel="nofollow noreferrer">https://psalm.dev/r/352e64ea95</a></p>
  <p>Is there a way to do it?</p>