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

Conversation

@avallete
Copy link
Member

What kind of change does this PR introduce?

Still in the idea to make a more straightforward, unified and strongly typed values for our tests:

  • Introduce zod schemas and re-use the same schemas to both:

    • infer the expected result type
    • Ensure that the runtime result type match the validation of the schema
  • Doing so, found a bug where self-referencing embeding via columns name would cause an unwanted intersection and fixed it.

@avallete avallete requested review from mandarini and soedirgo July 28, 2025 14:38
@@ -0,0 +1,12 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this is needed? Seems the tests work without it

Copy link
Member Author

@avallete avallete Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly because without this I would have difference between what's VSCode considered like an error and the result I would get when actually running the tests. With this being explicitly set, I get the same consistent result between the VSCode editor and the type-check results when running the tests with jest.

Comment on lines -425 to -431
parent_id:
| (number & {
description: string | null
id: number
parent_id: number | null
})
| null
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the kind of unwanted intersection that were created this number & {...}. It also cause all the "methods" of number to be available to the "results" (.toFixed, ...). This is now corrected by ensuring the result recursion won't use intersection but instead, always override the value by what's further down the recursion chain.

Comment on lines -531 to -535
type ExpectedType = Prettify<
Database['public']['Tables']['best_friends']['Row'] & {
first_user: string & Database['public']['Tables']['users']['Row']
}
>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid intersection now fixed.

Comment on lines +167 to +176
const ExpectedSchema = z.object({
username: z.string(),
messages: z.array(z.object({ id: z.number() })),
user_profiles: z.array(z.object({ id: z.number() })),
})
type ExpectedType = z.infer<typeof ExpectedSchema>
let result: Exclude<typeof res.data, null>
let expected: ExpectedType
expectType<TypeEqual<typeof result, typeof expected>>(true)
ExpectedSchema.parse(res.data)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is what the migration to zod looks like. The expectType remains, but now we also ensure the actual result match the expected result (at least pass zod validation).

This will make it easier to spot drift between runtime behaviour and type expectation that trying to visually match what's inside the toMatchSnapshot and the expectType definition.

@avallete avallete merged commit fa6c8e1 into master Jul 28, 2025
3 checks passed
avallete added a commit that referenced this pull request Jul 28, 2025
* chore(tests): use zod schemas for both type assertions and rutime results validations

* fix(types): self-reference relationship unwanted intersection

* chore: context for tsconfig.test.json

---------

Co-authored-by: Bobbie Soedirgo <[email protected]>
avallete added a commit that referenced this pull request Aug 5, 2025
Fixes regression introduced in #627
While fixing the invalid intersection for conflicting keys case
the Omit did lead to a huge increase in the recursive type complexity
Removing it bring back the corner case, but allow much more longer queries.

A test is now in place to ensure minimal coverage over the query complexities
we can handle before reaching infinite recursion errors.
avallete added a commit that referenced this pull request Aug 6, 2025
* fix(typegen): avoid possible infinite recursion error

- Add a fixed max depth to recursive types allowing Typescript to not raise
possible infinite recursion error too early.
- Add test to ensure that the provided fix remove this error from a recursive embeding

Related:
supabase/supabase-js#1354
supabase/supabase-js#1372
supabase/supabase-js#808

* fix(typegen): infinite recursion error

Fixes regression introduced in #627
While fixing the invalid intersection for conflicting keys case
the Omit did lead to a huge increase in the recursive type complexity
Removing it bring back the corner case, but allow much more longer queries.

A test is now in place to ensure minimal coverage over the query complexities
we can handle before reaching infinite recursion errors.

* chore: add types test watcher

* chore: watch over all src
@github-actions
Copy link

github-actions bot commented Aug 6, 2025

🎉 This PR is included in version 1.21.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants