Open golergka opened 3 years ago
That does look like inconvenient. I think a good way to solve this is to introduce a "required" spread parameter syntax. Queries that include such parameters should fail if one of the required params is an empty array.
One way to solve this issue is to force the generated type to be NonEmpty<T>
instead of Array<T>
, where NonEmpty
represents an array with at least one element.
Example of encoding NonEmpty
:
type NonEmpty<T> = [T, ...T[]]
Another way to solve this is to inject empty array literal, see https://stackoverflow.com/a/33717063/6587634
Over the last few months of using pgtyped, I've ran into several bugs that look something like this:
Because when
createThings
array is empty, I get an error:(Names of things are changed to respect my employer's NDA).
This is a painful bug, especially in cases where these arrays are empty only in very rare cases. How can we prevent things like this from happening?