-
-
Notifications
You must be signed in to change notification settings - Fork 364
[LiveComponent] Throw clear error when using union types for LiveProps #856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this problem exist for intersection types as well? (\ReflectionIntersectionType
)
I considered that, but I wrongly assumed that intersection types are only used for method argument types, to enforce an argument to implement two interfaces, and thus not for property types, which does not make much sense. However, I checked now, and it is allowed (although the use case might be less common imo). I updated the code, since it is possible for properties as well. |
@@ -71,6 +71,9 @@ public function createPropMetadatas(\ReflectionClass $class): array | |||
} | |||
|
|||
$type = $property->getType(); | |||
if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) { | |||
throw new \LogicException(sprintf('Union nor intersection types are not supported for LiveProps. You may want to change the type of property %s in %s.', $property->getName(), $property->getDeclaringClass()->getName())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new \LogicException(sprintf('Union nor intersection types are not supported for LiveProps. You may want to change the type of property %s in %s.', $property->getName(), $property->getDeclaringClass()->getName())); | |
throw new \LogicException(sprintf('Union or intersection types are not supported for LiveProps. You may want to change the type of property %s in %s.', $property->getName(), $property->getDeclaringClass()->getName())); |
Just to avoid the double-negative of nor
and not supported
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny wording tweak - but I think this is the correct approach. And we could always revisit later 👍
@weaverryan that's indeed a double negative 🙈 |
Thanks @sneakyvv! |
As mentioned in #853 (comment), supporting union types for LiveProps will be quite tricky. Given that, at least a clear error should be thrown.