-
-
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.
fix(types): Add types for QueryFilters which flow down to Query<> and…
… QueryKey/DataTag types (#8332) * Add types for QueryFilters which flow down to Query<> and QueryKey/DataTag types * ci: apply automated fixes * Add a type test * ci: apply automated fixes * Fix linting --------- Co-authored-by: Dominik Dorfmeister <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d28de3c
commit 422c879
Showing
3 changed files
with
68 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { describe, expectTypeOf, it } from 'vitest' | ||
import { QueryClient } from '../queryClient' | ||
import type { QueryFilters } from '../utils' | ||
import type { DataTag } from '../types' | ||
|
||
describe('QueryFilters', () => { | ||
it('should be typed if generics are passed', () => { | ||
type TData = { a: number; b: string } | ||
type TError = { message: string } | ||
|
||
const a: QueryFilters<TData, TError> = { | ||
predicate(query) { | ||
expectTypeOf(query.setData({ a: 1, b: '1' })).toEqualTypeOf<TData>() | ||
return true | ||
}, | ||
queryKey: ['key'] as DataTag<undefined, TData>, | ||
} | ||
|
||
const queryClient = new QueryClient() | ||
|
||
const data = queryClient.getQueryData(a.queryKey!) | ||
expectTypeOf(data).toEqualTypeOf<TData | undefined>() | ||
|
||
const error = queryClient.getQueryState(a.queryKey!)?.error | ||
expectTypeOf(error).toEqualTypeOf<Error | null | undefined>() // maybe one day this can return TError | ||
}) | ||
|
||
it('should be loose typed if generics are defaults', () => { | ||
const a: QueryFilters = { | ||
predicate(query) { | ||
expectTypeOf(query.setData({ a: 1, b: '1' })).toEqualTypeOf<unknown>() | ||
return true | ||
}, | ||
queryKey: ['key'], | ||
} | ||
|
||
const queryClient = new QueryClient() | ||
|
||
const data = queryClient.getQueryData(a.queryKey!) | ||
expectTypeOf(data).toEqualTypeOf<unknown>() | ||
|
||
const error = queryClient.getQueryState(a.queryKey!)?.error | ||
expectTypeOf(error).toEqualTypeOf<Error | null | undefined>() | ||
}) | ||
}) |
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