-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): prevent type errors and improve inference for dynamic que…
…ries on useQueries and useSuspenseQueries (#8624) * fix(react-query): prevent type errors and improve inference for dynamic queries on useQueries and useSuspenseQueries Previously, using useQueries and useSuspenseQueries with a dynamic array of mixed queries caused type errors. This commit ensures that type errors no longer occur and that the returned data is correctly inferred (e.g., as (number | boolean | undefined)[]) instead of unknown[]. * fix(react-query): improve type inference for useQueries and useSuspenseQueries results * fix(react-query): fix type of queries in useQueries and useSuspenseQueries * refactor: remove meaningless depths * test(react-query): move type only tests * test(react-query): fix type test error * fix(vue-query): prevent type errors and improve inference for dynamicqueries on useQueries * fix: prevent type errors and improve inference for dynamicqueries * fix: solid type tests not sure why, but compilation must run first with the current tsc version in case solid-query isn't built yet * fix: prevent type errors and improve inference for dynamic queries * chore: remove test * test(react-query): fix failing type tests * fix: fix test syntax error * test(react-query): remove tests for result[0].data * fix: change the result fallback to fix test fail * rollback(angular-query-experimental): restore injectQueries --------- Co-authored-by: Dominik Dorfmeister <[email protected]>
- Loading branch information
Showing
13 changed files
with
190 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/solid-query/src/__tests__/createQueries.test-d.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, expectTypeOf, it } from 'vitest' | ||
import { createQueries, queryOptions } from '..' | ||
import type { CreateQueryResult } from '..' | ||
|
||
describe('createQueries', () => { | ||
it('should return correct data for dynamic queries with mixed result types', () => { | ||
const Queries1 = { | ||
get: () => | ||
queryOptions({ | ||
queryKey: ['key1'], | ||
queryFn: () => Promise.resolve(1), | ||
}), | ||
} | ||
const Queries2 = { | ||
get: () => | ||
queryOptions({ | ||
queryKey: ['key2'], | ||
queryFn: () => Promise.resolve(true), | ||
}), | ||
} | ||
|
||
const queries1List = [1, 2, 3].map(() => ({ ...Queries1.get() })) | ||
const result = createQueries(() => ({ | ||
queries: [...queries1List, { ...Queries2.get() }], | ||
})) | ||
|
||
expectTypeOf(result).toEqualTypeOf< | ||
[ | ||
...Array<CreateQueryResult<number, Error>>, | ||
CreateQueryResult<boolean, Error>, | ||
] | ||
>() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.