Hilla Generated Types with in Array<DTOName | undefined> | undefied

In Hilla, most of my API will run objects. There will never be return from API with types like

Array<DTOName | undefined> | undefined

My responses will always be List | undefined

If I set package-info, this requires all the properties as well to be not undefined.

@NonNullApi
package com.myapp.application.api;

import org.springframework.lang.NonNullApi;

This causes many unncessary checks in TypeScripts to make sure that list does not have undefined objects.

I am ok with properties in DTOName being undefined.
Is there any way to acheieve this

List < DTOName > | undefined

what is your hilla version?

By default, Hilla does its best to translate Java semantics, so almost everything is nullable.
When using @NonNullApi, everything in the package becomes non-nullable by default, except specific cases like Optional.

I suggest you to play with nullability annotations. Starting from 24.7, we recommend to use those in org.specify.annotations, while before we had our ones in com.vaadin.hilla.

If most of your types are nullable, just use @NonNull to mark those who aren’t, i.e. List<@NonNull DTOName>.

Otherwise, mark your package as non-nullable using @NonNullApi and use @Nullable for the exceptions, i.e. @Nullable List<DTOName>.

3 Likes