- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript error on CRUD API functions with Supabase. Inferring from Supabase database types error? (Tables | Row) #582
Comments
@avallete Thank you for taking the time. I will go over your code see whats the best way of achieving this. However I would like to share my final solution see if this is a "professional" way of doing it. Is there something you wouldnt do in this code or suggest to change?? (beside the ID type and the tableName type. I know I may need to fix that) TYPES:
API CODE:
|
Hey there ! Sorry for the delay, I went trough your code and it look good to me and if it work for you then it's good 👍 Happy you found a solution that suite you and thank's for sharing it with the community. Closing the issue. |
Hello I have been struggling with my API query functions where I created my CRUD operations and typed them using different options.
SUMMARY:
I have 4 entities (services, articles, pets and objects) I wanted to re-use my CRUD so I infer types (data returned types and paylods) from "database.types.ts" but I can't make it work. It always complains about either my "payload" or my "return data" type.
### ERRORS :
Conversion of type '{ article: { Row: { approved: boolean; area: string | null; category: string; condition: string | null; created_at: string; deleted_at: string | null; description: string | null; event_at: string | null; ... 6 more ...; title: string; }; Insert: { ...; }; Update: { ...; }; Relationships: []; }; ... 7 more ...; servi...' to type 'Row<T>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Whats the best way to infer types for these CRUD? I tried lots of combination, it complains every single time. I have tried several ways of doing it, cant make it work. Its not detecting this. I cant continue with my app at the moment.
The only way was to cast the data frist as unknown first then the right type, but that is not recommended since it defeats the purpose of using typescript.
### NOTE. the returned data is typed like this (<SelectQueryError... ?). Is this the problem? Is it coming from postgress?:
The text was updated successfully, but these errors were encountered: