Skip to content

Commit baaeff3

Browse files
committed
add separate selectFromResult example
1 parent 898b114 commit baaeff3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/toolkit/src/query/tests/unionTypes.test-d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,4 +845,44 @@ describe('"Typed" helper types', () => {
845845
TypedUseMutationResult<string, void, typeof baseQuery>
846846
>().toMatchTypeOf(result)
847847
})
848+
849+
test('useQuery - defining selectFromResult separately', () => {
850+
const selectFromResult = (
851+
result: TypedUseQueryStateResult<string, void, typeof baseQuery>,
852+
) => ({ x: true })
853+
854+
const result = api.endpoints.getTest.useQuery(undefined, {
855+
selectFromResult,
856+
})
857+
858+
expectTypeOf(result).toEqualTypeOf<
859+
TypedUseQueryHookResult<
860+
string,
861+
void,
862+
typeof baseQuery,
863+
ReturnType<typeof selectFromResult>
864+
>
865+
>()
866+
})
867+
868+
test('useMutation - defining selectFromResult separately', () => {
869+
const selectFromResult = (
870+
result: Omit<
871+
TypedUseMutationResult<string, void, typeof baseQuery>,
872+
'reset' | 'originalArgs'
873+
>,
874+
) => ({ x: true })
875+
876+
const [trigger, result] = api.endpoints.mutation.useMutation({
877+
selectFromResult,
878+
})
879+
expectTypeOf(result).toEqualTypeOf<
880+
TypedUseMutationResult<
881+
string,
882+
void,
883+
typeof baseQuery,
884+
ReturnType<typeof selectFromResult>
885+
>
886+
>()
887+
})
848888
})

0 commit comments

Comments
 (0)