Skip to content

Commit 09ae5fd

Browse files
authored
Merge pull request #6 from scality/fix-mutationsWithRetry
chore: Update package.json version to 1.0.4
2 parents e320b35 + 11ffc0c commit 09ae5fd

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scality/react-chained-query",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "A wrapper of react-query useQuery hook allowing chained queries.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/useChainedMutations.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ type ChainedMutationsResults<T extends unknown[]> = T extends []
5151
? T
5252
: never;
5353

54+
type ChainedMutationsWithRetryResults<T extends unknown[]> = T extends []
55+
? []
56+
: T extends [infer Head, ...infer Tail]
57+
? [
58+
InferChainedMutation<Head> & {
59+
status: 'loading' | 'success' | 'error';
60+
retry: () => void;
61+
},
62+
...ChainedMutationsWithRetryResults<Tail>,
63+
]
64+
: T extends [infer Head]
65+
? [
66+
InferChainedMutation<Head> & {
67+
status: 'loading' | 'success' | 'error';
68+
retry: () => void;
69+
},
70+
]
71+
: T extends unknown[]
72+
? T
73+
: never;
74+
5475
/**
5576
* Extracts the variable type from a ChainedMutation type.
5677
* @template T - The ChainedMutation type.
@@ -149,16 +170,10 @@ export const useChainedMutations = <T extends any[]>({
149170
}): {
150171
mutate: () => void;
151172
computeVariablesForNext: ComputeVariablesForNext<T>;
152-
mutationsWithRetry: (ChainedMutation & {
153-
status: 'loading' | 'success' | 'error';
154-
retry: () => void;
155-
})[];
173+
mutationsWithRetry: [...ChainedMutationsWithRetryResults<T>];
156174
} => {
157175
const mutationsWithRetry = useRef<
158-
(ChainedMutation & {
159-
status: 'loading' | 'success' | 'error';
160-
retry: () => void;
161-
})[]
176+
[...ChainedMutationsWithRetryResults<T>]
162177
//@ts-expect-error initial value
163178
>(mutations);
164179
const go = (results: unknown[] = []) => {

0 commit comments

Comments
 (0)