-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(solid-query): infiniteQueryOptions (#7404)
* feat(solid-query): implemented infiniteQueryOptions * removed useless TOptions type * fix formatting --------- Co-authored-by: Dominik Dorfmeister <[email protected]>
- Loading branch information
Showing
5 changed files
with
288 additions
and
1 deletion.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
packages/solid-query/src/__tests__/createInfiniteQuery.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,109 @@ | ||
import { describe } from 'node:test' | ||
import { expectTypeOf, it } from 'vitest' | ||
import { type InfiniteData, dataTagSymbol } from '@tanstack/query-core' | ||
import { | ||
createInfiniteQuery, | ||
infiniteQueryOptions, | ||
} from '../createInfiniteQuery' | ||
import type { | ||
DefinedInitialDataInfiniteOptions, | ||
UndefinedInitialDataInfiniteOptions, | ||
} from '../createInfiniteQuery' | ||
|
||
const doNotRun = (_callback: () => void) => {} | ||
|
||
describe('infiniteQueryOptions', () => { | ||
it('should infer defined types', () => { | ||
const options = infiniteQueryOptions({ | ||
getNextPageParam: () => 10, | ||
queryKey: ['key'], | ||
queryFn: () => ({ wow: true }), | ||
initialData: { | ||
pageParams: [undefined], | ||
pages: [{ wow: true }], | ||
}, | ||
initialPageParam: 0, | ||
}) | ||
|
||
doNotRun(() => { | ||
expectTypeOf< | ||
InfiniteData< | ||
{ | ||
wow: boolean | ||
}, | ||
unknown | ||
> | ||
>(createInfiniteQuery(() => options).data) | ||
|
||
expectTypeOf< | ||
ReturnType< | ||
DefinedInitialDataInfiniteOptions< | ||
{ | ||
wow: boolean | ||
}, | ||
Error, | ||
InfiniteData< | ||
{ | ||
wow: boolean | ||
}, | ||
unknown | ||
>, | ||
Array<string>, | ||
number | undefined | ||
> | ||
> | ||
>(options) | ||
|
||
expectTypeOf(options.queryKey[dataTagSymbol]).toEqualTypeOf< | ||
InfiniteData<{ wow: boolean }> | ||
>() | ||
}) | ||
}) | ||
|
||
it('should work without defined types', () => { | ||
const options = infiniteQueryOptions({ | ||
getNextPageParam: () => undefined, | ||
queryKey: ['key'], | ||
queryFn: () => ({ wow: true }), | ||
initialPageParam: 0, | ||
}) | ||
|
||
doNotRun(() => { | ||
expectTypeOf< | ||
() => | ||
| InfiniteData< | ||
{ | ||
wow: boolean | ||
}, | ||
unknown | ||
> | ||
| undefined | ||
>(() => createInfiniteQuery(() => options).data) | ||
|
||
expectTypeOf< | ||
ReturnType< | ||
UndefinedInitialDataInfiniteOptions< | ||
{ | ||
wow: boolean | ||
}, | ||
Error, | ||
InfiniteData< | ||
{ | ||
wow: boolean | ||
}, | ||
unknown | ||
>, | ||
Array<string>, | ||
number | ||
> | ||
> | ||
>(options) | ||
|
||
expectTypeOf(options.queryKey[dataTagSymbol]).toEqualTypeOf< | ||
InfiniteData<{ | ||
wow: boolean | ||
}> | ||
>() | ||
}) | ||
}) | ||
}) |
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