Skip to content

Commit

Permalink
Fix types in connectQuery in case of source _Query_ with initialData
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Aug 17, 2024
1 parent 87af663 commit 6107570
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-hotels-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farfetched/core": patch
---

Fix types in `connectQuery` in case of source _Query_ with `initialData`
29 changes: 29 additions & 0 deletions packages/core/src/query/__tests__/connect_query.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,33 @@ describe('connectQuery', () => {
target: query2,
});
});

test('allows query with initialData to be used as source', () => {
const query1 = createQuery({
initialData: [],
async handler(ids: number[]) {
return Promise.resolve([1]);
},
});

const query2 = createQuery({
initialData: [],
async handler(ids: number[]) {
return Promise.resolve([1]);
},
});

connectQuery({
source: query1,
fn: (a) => {
a.params.forEach;
a.result.forEach;

return {
params: [1],
};
},
target: query2,
});
});
});
4 changes: 2 additions & 2 deletions packages/core/src/query/connect_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function connectQuery<Sources, Target extends Query<any, any, any, any>>(
} & (Target extends Query<infer P, any, any, any>
? P extends void
? { fn?: undefined; filter?: () => boolean }
: Sources extends Query<any, any, any>
: Sources extends Query<any, any, any, any>
? {
fn: (sources: {
result: RemoteOperationResult<Sources>;
Expand All @@ -32,7 +32,7 @@ export function connectQuery<Sources, Target extends Query<any, any, any, any>>(
params: RemoteOperationParams<Sources>;
}) => boolean;
}
: Sources extends Record<string, Query<any, any, any>>
: Sources extends Record<string, Query<any, any, any, any>>
? {
fn: (sources: {
[index in keyof Sources]: {
Expand Down

0 comments on commit 6107570

Please sign in to comment.