vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
867 stars 58 forks source link

`useFormPart`'s `value` and `setValue` do not respect nullability of related entity field #2507

Open cromoteca opened 1 month ago

cromoteca commented 1 month ago

Describe the bug

I have an entity with a property of type Player[] (not nullable). I noticed that, when using useFormPart, value and setValue use Player[] | undefined as type. This comes from BinderNode's type definitions: get value(): Value<M> | undefined and set value(value: Value<M> | undefined).

Expected-behavior

value and setValue should be cast to the correct type, even if BinderNode returns different type for internal reasons.

Reproduction

Define an entity like above and call useFormPart on it.

System Info

Hilla 24.5.0.alpha1

platosha commented 3 weeks ago

Seems like casting would not be compatible with nullable fields. Let's address after introducing Object Models, which support optionality on the model type level.

cromoteca commented 3 weeks ago

My idea was to cast to the entity type, so nullable fields should be compatible. But I cannot get the information from the model, as it seems that only the parent knows about optional values.