I noticed that the postgrest client has issues with error highlighting on insert/upsert calls when there is a type missmatch between the expected and provided properties.
I was able to trace this back to the overload defined on insert / upsert which is causing typescript to have problems with determining the correct signature if there's an error in the payload and therefore error-highlighting the whole function call:
As an example, if I define a function without any overload, the error highlights works way better:
And if I define my test function with an overload the same way as it is done in the client, it breaks again:
A solution would be either to unify both calls into a single signature (which would just mean that defaultToNull option would be defined unnecessarily for non-bulk operations) or to just split it into insert & insertBulk / upsert & upsertBulk or something like that.
Original post (less relevant than actual issue)
As far as I can see, functions like `insert` and `upsert` in the query builder use a generic type `Row` for the values to insert when in fact this type should not be necessary at all.
So instead of this:
https://github.com/supabase/postgrest-js/blob/c9cebf8a0a5a3c8dff4a511d70fd53079781f563/src/PostgrestQueryBuilder.ts#L101-L106
It should work better if it is defined like this instead:
```ts
insert(
values: Relation extends { Insert: unknown } ? Relation['Insert'] : never,
options?: {
count?: 'exact' | 'planned' | 'estimated'
}
): PostgrestFilterBuilder
```
This would improve type discovery a bit and improve error reporting.
The reason I say it's not required is because the generic type is only used for the input and not used anywhere on the output.
I noticed that the postgrest client has issues with error highlighting on insert/upsert calls when there is a type missmatch between the expected and provided properties. I was able to trace this back to the overload defined on insert / upsert which is causing typescript to have problems with determining the correct signature if there's an error in the payload and therefore error-highlighting the whole function call:
As an example, if I define a function without any overload, the error highlights works way better:![image](https://github.com/supabase/postgrest-js/assets/6547794/023a90ca-e56b-4052-86df-27ed7573261b)
And if I define my test function with an overload the same way as it is done in the client, it breaks again:![image](https://github.com/supabase/postgrest-js/assets/6547794/9034f112-43c0-4f6b-99f9-cd5e2b8a5267)
A solution would be either to unify both calls into a single signature (which would just mean that
defaultToNull
option would be defined unnecessarily for non-bulk operations) or to just split it intoinsert
&insertBulk
/upsert
&upsertBulk
or something like that.Original post (less relevant than actual issue)
As far as I can see, functions like `insert` and `upsert` in the query builder use a generic type `Row` for the values to insert when in fact this type should not be necessary at all. So instead of this: https://github.com/supabase/postgrest-js/blob/c9cebf8a0a5a3c8dff4a511d70fd53079781f563/src/PostgrestQueryBuilder.ts#L101-L106 It should work better if it is defined like this instead: ```ts insert( values: Relation extends { Insert: unknown } ? Relation['Insert'] : never, options?: { count?: 'exact' | 'planned' | 'estimated' } ): PostgrestFilterBuilder