Currently, I am attempting to utilize Supabase alongside TypeScript. However, I encounter an error when trying to use functions like insert(), update(), upsert(), etc. Specifically, the issue arises when declaring the object I want to declare: "Type <Restaurant> does not satisfy the constraint 'never'. ts(2344)"
Here is my code snippet:
type Restaurant = {
id: string;
name: string;
categories: string[];
open: boolean;
description: string;
}
const addRestaurant = async () => {
if (!user.value) return
const { data, error } = await supabaseClient
.from('restaurants')
.upsert<Restaurant>({
id: user.value.id,
name: name.value,
categories: arr,
open: status.value,
description: description.value
})
.select()
console.log(data, error);
}
The error pertains to <Restaurant>, and when I don't specify the type, a similar error occurs stating:
Argument of type '{ id: string; name: string; categories: string; open: boolean; description: string; }' is not assignable to parameter of type 'never[]'. Object literal may only specify known properties, and 'id' does not exist in type 'never[]'.ts(2345)
When hovering over the "upsert()" function, it seems like this is happening in the background:
PostgrestQueryBuilder<never, never>
Any suggestions on how to resolve this?
- I attempted specifying the Type of the object but realized that the functions [insert, update, upsert] require something else.
- I found out that adding a second parameter with an empty string temporarily resolves the error. However, modifying anything within it triggers the error again (which shouldn't be the ideal solution).
- The code functions with or without the second parameter, but the error persists during development - I prefer not to disable Typescript as I want to catch errors early.