fix(postgrest-js): preserve nullability when using JSON path (->) (#1635) #1939
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.
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
Screenshots/Examples:
N/A since it is a type-only change.
Breaking changes:
This PR contains no breaking changes.
📋 Checklist:
<type>(<scope>): <description>npx nx formatto ensure consistent code formattingAdditional 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