Skip to content

Commit 60a5dcc

Browse files
fix (postgrest-js): preserve nullability when using JSON path (->) (#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
1 parent 13af49b commit 60a5dcc

File tree

1 file changed

+1
-1
lines changed
  • packages/core/postgrest-js/src/select-query-parser

1 file changed

+1
-1
lines changed

packages/core/postgrest-js/src/select-query-parser/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ export type JsonPathToAccessor<Path extends string> = Path extends `${infer P1}-
618618
export type JsonPathToType<T, Path extends string> = Path extends ''
619619
? T
620620
: ContainsNull<T> extends true
621-
? JsonPathToType<Exclude<T, null>, Path>
621+
? JsonPathToType<Exclude<T, null>, Path> | null
622622
: Path extends `${infer Key}.${infer Rest}`
623623
? Key extends keyof T
624624
? JsonPathToType<T[Key], Rest>

0 commit comments

Comments
 (0)