Skip to content

Commit a9c6fd1

Browse files
committed
fix(postgrest): make new function inference mostly retro compatible
1 parent 9d96968 commit a9c6fd1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/core/postgrest-js/src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ export type GetRpcFunctionFilterBuilderByArgs<
4040
: // Otherwise, we attempt to match with one of the function definition in the union based
4141
// on the function arguments provided
4242
Args extends GenericFunction['Args']
43-
? LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
43+
? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
44+
// we fallback to the last function definition matched by name
45+
IsNever<
46+
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
47+
> extends true
48+
? LastOf<Schema['Functions'][FnName]>
49+
: // Otherwise, we use the arguments based function definition narrowing to get the right value
50+
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
4451
: // If we can't find a matching function by args, we try to find one by function name
4552
ExtractExactFunction<Schema['Functions'][FnName], Args> extends GenericFunction
4653
? ExtractExactFunction<Schema['Functions'][FnName], Args>

0 commit comments

Comments
 (0)