Skip to content

Commit

Permalink
fix: repair contextQueries not working with possibly undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorales committed Feb 25, 2024
1 parent 81cd141 commit a7eb8d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-items-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lukemorales/query-key-factory": patch
---

Fix `contextQueries` not working with possibly undefined values
8 changes: 4 additions & 4 deletions src/create-query-keys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ describe('createQueryKeys |> extrapolating "contextQueries" nesting', () => {
contextQueries: {
nested1: null,
nested2: ['context-prop-2'],
nested3: (nestedValue: string) => ({
nested3: (nestedValue?: string) => ({
queryKey: [nestedValue],
contextQueries: {
nested4: null,
Expand Down Expand Up @@ -770,7 +770,7 @@ describe('createQueryKeys |> extrapolating "contextQueries" nesting', () => {
_def: readonly ['test', 'prop', string, 'nested2'];
queryKey: readonly ['test', 'prop', string, 'nested2', string];
};
nested3: { _def: readonly ['test', 'prop', string, 'nested3'] } & ((nestedValue: string) => {
nested3: { _def: readonly ['test', 'prop', string, 'nested3'] } & ((nestedValue?: string) => {
queryKey: readonly ['test', 'prop', string, 'nested3', string];
_ctx: {
nested4: { queryKey: readonly ['test', 'prop', string, 'nested3', string, 'nested4'] };
Expand All @@ -793,10 +793,10 @@ describe('createQueryKeys |> extrapolating "contextQueries" nesting', () => {
};
nested3: {
_def: readonly ['test', 'prop', string, 'nested3'];
queryKey: readonly ['test', 'prop', string, 'nested3', string];
queryKey: readonly ['test', 'prop', string, 'nested3', string | undefined];
_ctx: {
nested4: {
queryKey: readonly ['test', 'prop', string, 'nested3', string, 'nested4'];
queryKey: readonly ['test', 'prop', string, 'nested3', string | undefined, 'nested4'];
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type AnyMutableOrReadonlyArray = any[] | readonly any[];

export type Tuple = [ValidValue, ...Array<ValidValue | undefined>];
export type Tuple = [ValidValue | undefined, ...Array<ValidValue | undefined>];

export type KeyTuple = Tuple | Readonly<Tuple>;

Expand Down

0 comments on commit a7eb8d2

Please sign in to comment.