-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Wrong type for joins with one-to-one relationships #471
Comments
I'm using this as a workaround for now: export function cast<T>(notAnArray: T[]): T {
return notAnArray as T;
} And then: console.log(cast(profile_result.data.customers).stripe_customer_id) |
Update: I've changed my workaround to this: export function fixOneToOne<T>(objectOrNull: T[]): T | null {
return (objectOrNull as T) || null;
} I've changed the return type to In the example above, the correct type should be: {
stripe_customer_id: string;
} | null |
I encountered the same issue today and I found another workaround.
|
I am experiencing the exact same issue. As my query is rather nested, workarounds are very inconvenient... Does anyone know, whether an older version does not have this bug included? |
Seems to still be an issue |
Same problem over here, is there a fix for this issue?? |
Same problem here. |
Yep, same here! Please fix when possible |
Still a problem, please fix! |
same problem for me |
Please fix! |
Hi there, I believe this bug might have been fixed. I tried to reproduce the issue with the following setup: SQL Setup:-- Create profiles table
CREATE TABLE profiles (
id TEXT PRIMARY KEY
);
-- Create customers table with a foreign key to profiles
CREATE TABLE customers (
id TEXT PRIMARY KEY REFERENCES profiles(id),
stripe_customer_id TEXT UNIQUE
);
INSERT INTO profiles (id) VALUES ('1');
INSERT INTO customers (id, stripe_customer_id) VALUES ('1', '1'); TypeScript Test:const profile_result = await supabase
.from('profiles')
.select('id, customers (stripe_customer_id)')
.single();
console.log(profile_result.data); With this setup, I got the expected results both from a types and runtime perspective: TypeScript Types:const profile_result: PostgrestSingleResponse<{
id: string;
customers: {
stripe_customer_id: string | null;
} | null;
}> Runtime Output:{
"id": "1",
"customers": {
"stripe_customer_id": "1"
}
} Could you please check on your end if it's fixed for you as well? |
Looks like it's fixed yeah |
Absolutely not fixed. Tables CREATE TABLE companies (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
scraped_site_id UUID,
description TEXT,
);
CREATE TABLE surveys (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
company_id UUID REFERENCES companies(id),
);
CREATE TABLE scraped_sites (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
raw_data JSONB
); Typescript const { data, error } = await supabase
.from("surveys")
.select(
`
company:companies ( name, description, scraped_site:scraped_sites ( raw_data ) )
`
)
.eq("id", surveyId)
.single(); Last version used (2.45.4) |
I think it will be difficult to investigate without also giving the related SQL schema.
|
You are right, I updated my previous message to include the tables to reproduce the issue. |
Seems fixed with Using |
Hi there, would you mind providing a minimal reproduction example of your case with both the SQL to generate the relation and the select query you're running ?
I'm locking this issue as the original problem is fixed and similar ones will likely be under a different scope. Please open a new issue following the typing bug reporting infos:
|
For the I'll check now to see whether |
Bug report
Describe the bug
I have a
profiles
and acustomers
table, with a one-to-one relationship:When doing a join between these, TypeScript thinks the type of
customers
is this:But when I run the code, this is the actual type I get:
So when accessing the
stripe_customer_id
property, I get this type error:To Reproduce
Expected behavior
The TypeScript type should not be an array for one-to-one relationships. It should match the actual type
System information
Additional context
Related:
The text was updated successfully, but these errors were encountered: