Blazor can't use EventCallback with array TypeParam value #7476
Open
Description
I've isolated my issue to a small bit of code, having a component like this:
MyArrValComp.razor
@typeparam TKey
@code {
[Parameter]
public TKey[] Value { get; set; }
[Parameter]
public EventCallback<TKey[]> ValueChanged { get; set; }
}
I call the component like in Index.razor
like this:
<MyArrValComp @bind-Value="val1" TKey="int"/>
@code
{
private int[] val1 = new []{ 1, 2, 3 };
}
and it won't compile, it will give misleading error messages like this:
The type or namespace name 'TKey' could not be found (are you missing a using directive ... Index.razor.g.cs
The type or namespace name 'TKey' could not be found (are you missing a using ... Index.razor
after experimentation I realized that Arrays won't work with EventCallback I need to use IEnumerable<T>
instead, that fixed it.
- so the error messages are definitely misleading,
- also not sure if you're aware about this issue, I haven't noticed in the docs saying that we can't use arrays with
EventCallback
- is it possible to bind to any collection, I was hoping since Value and ValueChanged are
IEnumerable<T>
I'll be able to bind to any collection (includingT[]
) but no, it only acceptsIEnumerable<T>
?