Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Conversation

avallete
Copy link
Member

@avallete avallete commented Feb 21, 2025

  • When a relation doesn't exist, or that type inference fail to resolve it the new type should be the source of truth for the result. In such case, we don't "merge" the properties together, but just replace the error with the user provided type.
  • When chaining the override with .maybeSingle preserve the optionality of the result
  • Allow merging between literal object and non literal one eg:
// Given some property like { someProperty: Record<string, Json | null> } // calling overrideType<{ someProperty: { literalProperty: string } }>() // result in: { [key: string]: Json | null someProperty: { literalProperty: string } } 
When a relation doesn't exist, or that type inference fail to resolve it the new type should be the source of truth for the result
@avallete avallete force-pushed the avallete/fix-override-on-invalid-relations branch from 8e0a0fc to 29e8c96 Compare February 23, 2025 16:14
@avallete avallete merged commit 1f93ee5 into master Feb 24, 2025
2 checks passed
Copy link

🎉 This PR is included in version 1.19.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jdgamble555
Copy link

@avallete - Why not have this work with single() as well?

J

@avallete
Copy link
Member Author

@avallete - Why not have this work with single() as well?

J

This should work with single() as well (test is here:

// Test merging and replacing existing field types in object result
{
const result = await postgrest
.from('users')
.select()
.single()
.overrideTypes<{ username: number }>()
if (result.error) {
throw new Error(result.error.message)
}
let data: typeof result.data
expectType<
TypeEqual<
typeof data,
{
username: number
data: CustomUserDataType | null
age_range: unknown
catchphrase: unknown
status: 'ONLINE' | 'OFFLINE' | null
}
>
>(true)
}
)

Difference here is that maybeSingle should always result in an optional (object | null) while single() should give a non null result.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3 participants