Skip to content

Conversation

@mandarini
Copy link
Contributor

Original Author: @dev-hari-prasad
Moved from: #1939

Description:
What changed?
Fixed the type inference for JSON path selections (->) by adding | null when 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 null when the whole column is null, so the types were unsafe.
This patch brings the inferred type in line with actual behavior.

Closes/Fixes #1635

dev-hari-prasad and others added 10 commits January 8, 2026 14:51
…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.
@mandarini mandarini requested review from a team as code owners January 8, 2026 13:13
@github-actions github-actions bot added the postgrest-js Related to the postgrest-js library. label Jan 8, 2026
@mandarini mandarini requested a review from avallete January 8, 2026 13:14
@mandarini mandarini self-assigned this Jan 8, 2026
@coveralls
Copy link

Coverage Status

coverage: 81.006%. remained the same
when pulling 7bb36a5 on fix/Null-should-be-included-in-return-type
into cf0cc8a on master.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 12, 2026

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2011

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2011

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2011

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2011

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2011

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2011

commit: 7bb36a5

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

Labels

postgrest-js Related to the postgrest-js library. trigger: preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Null should be included in return type when using json path (->)

5 participants