Skip to content

Conversation

@dev-hari-prasad
Copy link

@dev-hari-prasad dev-hari-prasad commented Dec 10, 2025

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

Screenshots/Examples:
N/A since it is a type-only change.

Breaking changes:
This PR contains no breaking changes.

📋 Checklist:

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run npx nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

Additional notes:
The change is intentionally minimal and only affects the nullable branch of JsonPathToType.
It preserves existing behavior for non-nullable JSON columns while correctly reflecting actual return values for nullable ones.

CC @avallete & @mandarini

…upabase#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: supabase#1635
@dev-hari-prasad dev-hari-prasad requested review from a team as code owners December 10, 2025 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant