Skip to content

[LiveComponent] Error Union or intersection types are not supported for LiveProps with TypeInfo 7.1 #2827

Closed
@Kocal

Description

@Kocal

While working on #2824, I created a live component with many #[LiveProp]:

#[AsLiveComponent]
final class TonsOfLiveProp
{
    use DefaultActionTrait;

    #[LiveProp]
    public ?string $description = null;
}

and I've faced this issue:
Image

Given the following code:

if ($type instanceof UnionType && !$type instanceof NullableType || $type instanceof IntersectionType) {
    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".', $propertyName, $className));
}

It can not works because NullableType has been introduced in TypeInfo 7.2, !$type instanceof NullableType fails because the class NullableType does not exist, and it throws the exception.

As a workaround, I believe we can use replace !$type instanceof NullableType by !$type->isNullable().

I'm wondering why the CI didn't catch the issue, we have a nullable-string LiveProp in our fixtures... 🤔

cc @mtarld

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions