From 8590dfbe31f480ff6ee5d1d683c832a815700526 Mon Sep 17 00:00:00 2001 From: Nazarii Shvets <74127809+NazariiShvets@users.noreply.github.com> Date: Wed, 11 Oct 2023 08:57:10 +0300 Subject: [PATCH] fix: Fix passing to connectQuery.target query with initialData (#378) * fix: Fix passing to connectQuery.target query with initialData * test: add tests for issue 377 * lint: format * Allow passing to connectQuery query with initialData --- .changeset/good-bees-smile.md | 5 +++++ .../query/__tests__/connect_query.test-d.ts | 21 ++++++++++++++++++- packages/core/src/query/connect_query.ts | 4 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .changeset/good-bees-smile.md diff --git a/.changeset/good-bees-smile.md b/.changeset/good-bees-smile.md new file mode 100644 index 000000000..5591c476c --- /dev/null +++ b/.changeset/good-bees-smile.md @@ -0,0 +1,5 @@ +--- +'@farfetched/core': patch +--- + +Allow passing to connectQuery query with initialData diff --git a/packages/core/src/query/__tests__/connect_query.test-d.ts b/packages/core/src/query/__tests__/connect_query.test-d.ts index 034c81ade..45697c654 100644 --- a/packages/core/src/query/__tests__/connect_query.test-d.ts +++ b/packages/core/src/query/__tests__/connect_query.test-d.ts @@ -1,4 +1,4 @@ -import { createStore, Store, attach, Effect } from 'effector'; +import { createStore, Store, attach, Effect, createEffect } from 'effector'; import { describe, test, expectTypeOf } from 'vitest'; import { createQuery } from '../create_query'; @@ -190,4 +190,23 @@ describe('connectQuery', () => { target: someTargetQuery, }); }); + + test('can use query with initialData', () => { + type Query1Data = { foo: string }; + type Query2Data = { bar: string }; + + const query1 = createQuery({ + effect: createEffect((): Query1Data => ({ foo: 'foo' })), + }); + + const query2 = createQuery({ + initialData: { bar: '42' } as Query2Data, + effect: createEffect((): Query2Data => ({ bar: 'bar' })), + }); + + connectQuery({ + source: query1, + target: query2, + }); + }); }); diff --git a/packages/core/src/query/connect_query.ts b/packages/core/src/query/connect_query.ts index 64b9d4c03..052833245 100644 --- a/packages/core/src/query/connect_query.ts +++ b/packages/core/src/query/connect_query.ts @@ -12,11 +12,11 @@ type NonExtendable = { [K in string]: never; }; -export function connectQuery>( +export function connectQuery>( args: { source: Sources; target: Target | [...Target[]]; - } & (Target extends Query + } & (Target extends Query ? P extends void ? { fn?: undefined } : Sources extends Query