-
-
Notifications
You must be signed in to change notification settings - Fork 332
Inferred types for nullable columns after not null checks should be non-nullable #1360
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
Comments
Hi @chesterhow, Thanks for bringing this up! It’s definitely an interesting idea, but I don’t see us implementing this anytime soon. Here’s why: Implementing this would mean we’d need to replicate the full filtering logic of PostgREST within the TypeScript type system. Not only would that be pretty complex, but it could also lead to performance issues, especially when dealing with dynamic filters. Another thing to consider is consistency. If we were to handle const { data } = await supabase
.from("blog_posts")
.select("*")
.eq("title", 'somevalue');
const data: {
id: string;
title: string; // <--- Should this now only allow "somevalue" as the type?
created_at: string;
}[] | null As you can see, this could quickly snowball into a maintenance challenge, and we’d need to ensure it works seamlessly across all operators and edge cases. For now, we recommend handling these cases manually in your code to ensure type safety. We’ll keep this in mind as we continue improving the library, though! |
Hey @avallete, thanks for sharing more about the constraints of implementing this! 👀 May I know what is the recommended approach to deal with typing limitations like these? Should I override types using |
Hey @chesterhow ! Indeed using |
This comment has been minimized.
This comment has been minimized.
When I saw it, I thought it was a bug, it would be nice to mention it in the documentation 👀 mention that you can use |
Yes, we added a new method mentioned here: https://supabase.com/docs/guides/api/rest/generating-types#using-typescript-type-definitions And in the reference docs here: https://supabase.com/docs/reference/javascript/db-returns
However I want to mention that this is classified as a bug, we might still have this fixed in the future. But we still need to think it through. That's why the issue stays open so it can be discussed over. |
@avallete Thanks 😄 My 2c here is that maybe creating a new method |
Bug report
Describe the bug
For nullable columns, even if the query includes a not null check (e.g.
.not("column_name", "is", null)
), the inferred return type for that column is still nullable.To Reproduce
blog_posts
table with a nullable column,published_at
.published_at
field indata
is still typed as nullable.Expected behavior
Inferred type for
published_at
should not be nullable.System information
The text was updated successfully, but these errors were encountered: