Skip to content

[LiveComponent] Support UnionTypes for LiveProps #853

Closed
@sneakyvv

Description

@sneakyvv

Problem

Call to undefined method ReflectionUnionType::getName()

Cause

https://github.com/symfony/ux/blob/2.x/src/LiveComponent/src/Metadata/LiveComponentMetadataFactory.php#L77 assuming to work with a ReflectionNamedType.

Reproduce

Create a LiveComponent with

#[LiveProp] public int|string $someProperty;

Use it somewhere

Expected behavior

Either:

  1. Support using UnionTypes for LiveProps
  2. Throw clear error that UnionTypes are not supported

I want to contribute, but am not sure if option 1 or 2 is desired. The current $metadatas array is keyed by the property name and is flat, i.e. does not allow multiple types for one property (nor does the LivePropMetadata object), so allowing union types (option 1) will require some changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions