You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, I love the package and have been using it for all my projects for quite some time now.
In my current project, I came across the need to specify union types for a DataCollection but noticed a lack of support for it.
Since a single array might sometimes contain a list of different entities, it would be very useful to be able to type these in the declaration. For example: #[DataCollectionOf(FilterItemData::class, FilterRangeItemData::class, FilterListData::class, FilterPriceItemData::class)].
I’ve resorted to using plain arrays for this, but it would be great to have native support for union types, as this situation arises from time to time.
Example:
A list of filters of different types:
class FilterListData extends Data
{
publicfunction__construct(
publicstring$name,
public ?string$type,
public ?int$id,
/** * @var array<FilterItemData|FilterRangeItemData|FilterListData|FilterPriceItemData> */publicarray$items,
) {}
}
A better way?
class FilterListData extends Data
{
publicfunction__construct(
publicstring$name,
public ?string$type,
public ?int$id,
#[DataCollectionOf(FilterItemData::class, FilterRangeItemData::class, FilterListData::class, FilterPriceItemData::class)]
publicarray$items,
) {}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First of all, I love the package and have been using it for all my projects for quite some time now.
In my current project, I came across the need to specify union types for a DataCollection but noticed a lack of support for it.
Since a single array might sometimes contain a list of different entities, it would be very useful to be able to type these in the declaration. For example:
#[DataCollectionOf(FilterItemData::class, FilterRangeItemData::class, FilterListData::class, FilterPriceItemData::class)]
.I’ve resorted to using plain arrays for this, but it would be great to have native support for union types, as this situation arises from time to time.
Example:
A list of filters of different types:
A better way?
Beta Was this translation helpful? Give feedback.
All reactions