Skip to content
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

chore(types): make types retrocompatible to typescript 4.5.5 #571

Merged
merged 16 commits into from
Nov 6, 2024

Conversation

avallete
Copy link
Member

@avallete avallete commented Nov 1, 2024

What kind of change does this PR introduce?

One of the probable reason causing the number of issues we had with the new inference is probably the use in our tests of typescript ~4.7, in supabase-js we can see the version of typescript is 4.5.5.

This PR is here to reduce the migration friction by allowing the new parser to be retro-compatible with lower typescript version, down to 4.5.5 (I tested down to 4.3.3).

The main change across all was to get rid of the new convenient infer X extends Y syntax only available in typescript 4.7 and higher.

What is the current behavior?

Please link any relevant issues here.

What is the new behavior?

Feel free to include screenshots if it includes visual changes.

Additional context

Add any other context or screenshots.

package.json Show resolved Hide resolved
@soedirgo
Copy link
Member

soedirgo commented Nov 5, 2024

@avallete can you limit the change to infer X extends Y replacements? There's a bunch of other changes here that seem unrelated (never replacements, Node -> Node['type'], etc.)

@avallete
Copy link
Member Author

avallete commented Nov 5, 2024

@avallete can you limit the change to infer X extends Y replacements? There's a bunch of other changes here that seem unrelated (never replacements, Node -> Node['type'], etc.)

I'll try but:

  1. The Node -> Node['type'] change is here because the PR is based over this one where I responded here about why I think it's still necessary.

  2. I'll look into the never I mainly did it to ease the reporting and debugging process (it's easier to look for a single unique error string in a specific line than "any never" in the code), and only kept it at place where changing it would have required logic changes somewhere else. But I can revert that and keep the never if you confirm that's what you want those are the places where I have introduced "unrelated never":

https://github.com/supabase/postgrest-js/pull/571/files#diff-5e58fb7db093dc508e6abb63dd5488067ce801a1abbcb5a50644050d106ff1edL174-R179
https://github.com/supabase/postgrest-js/pull/571/files#diff-5e58fb7db093dc508e6abb63dd5488067ce801a1abbcb5a50644050d106ff1edL259-R266

  1. Also note that some of the changes notably in the tests is because of downgrading TS to 4.5.5, where function() !== function(undefined) and null narrowing wasn't the same.

Base automatically changed from fix/infer-default-result-for-untyped-client to master November 5, 2024 08:24
@avallete avallete changed the base branch from master to fix/spread-and-embeding-combination November 5, 2024 08:36
Comment on lines +468 to +476
export type FindJoinTableRelationship<
Schema extends GenericSchema,
CurrentTableOrView extends keyof TablesAndViews<Schema> & string,
FieldName extends string
> = ResolveJoinTableRelationship<Schema, CurrentTableOrView, FieldName> extends infer Result
? [Result] extends [never]
? false
: Result
: never
Copy link
Member Author

Choose a reason for hiding this comment

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

Make it consistent with the other FindXXRelationship that return a plain false if no relationship were found instead of never.

@@ -81,7 +81,7 @@ type SelectQueryFromTableResult<
let expected: {
msgs: {
id: number
message_details: SelectQueryError<`Could not embed because more than one relationship was found for 'messages' and '${string}' you need to hint the column with messages!<columnName> ?`>
message_details: SelectQueryError<'could not find the relation between messages and message_details'>
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 one was actually invalid given the database definition. I added a runtime test for it and adapted the expected error message accordingly.

@avallete
Copy link
Member Author

avallete commented Nov 5, 2024

@soedirgo

I've rebased this one over the correct branch so the diff should be much more focus on the actual changes for 4.5.5 compatibility.

Also reverted some noise with the never replacement / new errors that wasn't necessary to the conversion.

Note that this PR should be merged after the one it base itself of: #569

@soedirgo soedirgo changed the base branch from fix/spread-and-embeding-combination to master November 6, 2024 07:32
@soedirgo soedirgo merged commit cc9344a into master Nov 6, 2024
1 check passed
@soedirgo soedirgo deleted the fix/make-types-retrocompatible-to-4-5-5 branch November 6, 2024 07:35
Copy link

github-actions bot commented Nov 6, 2024

🎉 This PR is included in version 1.17.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants