-
Notifications
You must be signed in to change notification settings - Fork 560
fix(postgrest): preserve nullability when using JSON path #2011
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
Open
mandarini
wants to merge
10
commits into
master
Choose a base branch
from
fix/Null-should-be-included-in-return-type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,202
−85
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…1635) The JSON path resolver (JsonPathToType) stripped `null` using Exclude<T, null> but never added it back to the resulting type. This caused `.select('col->a')` to infer a non-nullable type even when the underlying JSON column was nullable. Example: json_col: { a: string } | null .select('json_col->a') // inferred `string` instead of `string | null` This patch re-attaches `| null` when the root JSON column contains null, ensuring correct type inference for nullable JSON columns and nullable nested paths. Fixes: #1635
Added tests to verify JsonPathToType correctly returns T | null when accessing paths on nullable JSON columns. Also updated existing tests to reflect the new nullable behavior in type expectations.
`supabase` cli isn't necesseraly generally available on the machine we run the tests on. This allows to have all necessary things we need to run the tests versioned into the package.json and installable with a single command.
5 tasks
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Original Author: @dev-hari-prasad
Moved from: #1939
Description:
What changed?
Fixed the type inference for JSON path selections (
->) by adding| nullwhen the underlying JSON column can be null.Why was this change needed?
When selecting a JSON path from a nullable JSON column, the generated TypeScript types incorrectly assumed the value could never be null.
In reality, the runtime returns
nullwhen the whole column is null, so the types were unsafe.This patch brings the inferred type in line with actual behavior.
Closes/Fixes #1635