Skip to content

Commit a7eb8d2

Browse files
committed
fix: repair contextQueries not working with possibly undefined values
1 parent 81cd141 commit a7eb8d2

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.changeset/fresh-items-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@lukemorales/query-key-factory": patch
3+
---
4+
5+
Fix `contextQueries` not working with possibly undefined values

src/create-query-keys.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ describe('createQueryKeys |> extrapolating "contextQueries" nesting', () => {
727727
contextQueries: {
728728
nested1: null,
729729
nested2: ['context-prop-2'],
730-
nested3: (nestedValue: string) => ({
730+
nested3: (nestedValue?: string) => ({
731731
queryKey: [nestedValue],
732732
contextQueries: {
733733
nested4: null,
@@ -770,7 +770,7 @@ describe('createQueryKeys |> extrapolating "contextQueries" nesting', () => {
770770
_def: readonly ['test', 'prop', string, 'nested2'];
771771
queryKey: readonly ['test', 'prop', string, 'nested2', string];
772772
};
773-
nested3: { _def: readonly ['test', 'prop', string, 'nested3'] } & ((nestedValue: string) => {
773+
nested3: { _def: readonly ['test', 'prop', string, 'nested3'] } & ((nestedValue?: string) => {
774774
queryKey: readonly ['test', 'prop', string, 'nested3', string];
775775
_ctx: {
776776
nested4: { queryKey: readonly ['test', 'prop', string, 'nested3', string, 'nested4'] };
@@ -793,10 +793,10 @@ describe('createQueryKeys |> extrapolating "contextQueries" nesting', () => {
793793
};
794794
nested3: {
795795
_def: readonly ['test', 'prop', string, 'nested3'];
796-
queryKey: readonly ['test', 'prop', string, 'nested3', string];
796+
queryKey: readonly ['test', 'prop', string, 'nested3', string | undefined];
797797
_ctx: {
798798
nested4: {
799-
queryKey: readonly ['test', 'prop', string, 'nested3', string, 'nested4'];
799+
queryKey: readonly ['test', 'prop', string, 'nested3', string | undefined, 'nested4'];
800800
};
801801
};
802802
};

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type AnyMutableOrReadonlyArray = any[] | readonly any[];
22

3-
export type Tuple = [ValidValue, ...Array<ValidValue | undefined>];
3+
export type Tuple = [ValidValue | undefined, ...Array<ValidValue | undefined>];
44

55
export type KeyTuple = Tuple | Readonly<Tuple>;
66

0 commit comments

Comments
 (0)