Using @psalm-if-this-is
for generic class conversion
#10864
Shira-3749
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello.
I'm trying to to add some conversion utility methods to a generic
Collection
class, such asasObjects()
returning a more specific collection type.I've tried to use
@psalm-if-this-is self<object>
to preventasObjects()
from being called on an incompatible collection type, but I've ran into issues when the template is invariant:https://psalm.dev/r/485bd7707a
The
InvalidTemplateParam
could be ignored, but I'm also gettingIfThisIsMismatch
on the call site which is a problem.Since
@psalm-if-this-is
doesn't change the type of$this
after the call, shouldn't it be able to assert any type regardless of variance?Beta Was this translation helpful? Give feedback.
All reactions