Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/createQueryClient.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ describe('useQuery', () => {
const placeholder = 'placeholder' as const
const action = () => response

const queryA = useQuery(action, [])
const queryA = useQuery(action, () => [])
expectTypeOf(queryA.data).toEqualTypeOf<typeof response | undefined>()

const queryB = useQuery(action, [], { placeholder })
const queryB = useQuery(action, () => [], { placeholder })
expectTypeOf(queryB.data).toEqualTypeOf<typeof response | typeof placeholder>()

const queryC = await useQuery(action, [])
const queryC = await useQuery(action, () => [])
expectTypeOf(queryC.data).toEqualTypeOf<typeof response>()

const queryD = await useQuery(action, [], { placeholder })
const queryD = await useQuery(action, () => [], { placeholder })
expectTypeOf(queryD.data).toEqualTypeOf<typeof response>()
})
})
Expand Down
24 changes: 12 additions & 12 deletions src/createQueryClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ describe('useQuery', () => {
const action = vi.fn(() => response)
const { useQuery } = createQueryClient()

const query = await useQuery(action, [])
const query = await useQuery(action, () => [])

expect(query.data).toBe(response)
})
Expand All @@ -280,7 +280,7 @@ describe('useQuery', () => {
throw new Error('test')
})
const { useQuery } = createQueryClient()
const value = useQuery(action, [])
const value = useQuery(action, () => [])

await expect(value).rejects.toThrow('test')
})
Expand Down Expand Up @@ -339,8 +339,8 @@ describe('useQuery', () => {
const action2 = vi.fn(() => false)
const { useQuery } = createQueryClient()

const query1 = useQuery(action1, [])
const query2 = useQuery(action2, [])
const query1 = useQuery(action1, () => [])
const query2 = useQuery(action2, () => [])

await vi.runOnlyPendingTimersAsync()

Expand All @@ -353,7 +353,7 @@ describe('useQuery', () => {
const response = Symbol('response')
const { useQuery } = createQueryClient()

const value = useQuery(() => response, [], { placeholder })
const value = useQuery(() => response, () => [], { placeholder })

expect(value.data).toBe(placeholder)

Expand All @@ -368,7 +368,7 @@ describe('useQuery', () => {
const action = vi.fn(() => response)
const { useQuery } = createQueryClient()

const query = useQuery(action, [], { immediate: true })
const query = useQuery(action, () => [], { immediate: true })

await vi.runOnlyPendingTimersAsync()

Expand All @@ -381,7 +381,7 @@ describe('useQuery', () => {
const action = vi.fn(() => response)
const { useQuery } = createQueryClient()

const query = useQuery(action, [], { immediate: false })
const query = useQuery(action, () => [], { immediate: false })

await vi.runOnlyPendingTimersAsync()

Expand All @@ -395,7 +395,7 @@ describe('useQuery', () => {
const action = vi.fn(() => response)
const { useQuery } = createQueryClient()

const query = useQuery(action, [], { immediate: false, placeholder })
const query = useQuery(action, () => [], { immediate: false, placeholder })

await vi.runOnlyPendingTimersAsync()

Expand All @@ -408,7 +408,7 @@ describe('useQuery', () => {
const action = vi.fn(() => response)
const { useQuery } = createQueryClient()

const query = useQuery(action, [], { immediate: false })
const query = useQuery(action, () => [], { immediate: false })

await vi.runOnlyPendingTimersAsync()

Expand All @@ -426,7 +426,7 @@ describe('useQuery', () => {
const action = vi.fn(() => response)
const { useQuery } = createQueryClient()

const query = useQuery(action, [], { immediate: false })
const query = useQuery(action, () => [], { immediate: false })

await vi.runOnlyPendingTimersAsync()

Expand All @@ -448,7 +448,7 @@ describe('useQuery', () => {
})
const { useQuery } = createQueryClient()

const query = useQuery(action, [], { immediate: false })
const query = useQuery(action, () => [], { immediate: false })

await vi.runOnlyPendingTimersAsync()

Expand Down Expand Up @@ -489,7 +489,7 @@ describe('defineQuery', () => {

const { useQuery } = defineQuery(action)

const value = useQuery([])
const value = useQuery(() => [])

await vi.runOnlyPendingTimersAsync()

Expand Down
18 changes: 9 additions & 9 deletions src/tag.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ import { tag } from './tag'
test('tag function returns a tag when no callback is provided', () => {
const value = tag()

expectTypeOf(value).toMatchTypeOf<QueryTag>()
expectTypeOf(value).toExtend<QueryTag>()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because of the vitest deprecation yeah? What's the other option? Extends seems like the looser option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. Type hints for deprecated toMatchTypeOf suggested toExtend, didn't try too hard to find a better assertion 🤷

})

test('tag function returns a tag factory when a callback is provided', () => {
const factory = tag((string: string) => string)

expectTypeOf(factory).toMatchTypeOf<QueryTagFactory<unknown, string>>()
expectTypeOf(factory).toExtend<QueryTagFactory<unknown, string>>()

const value = factory('foo')

expectTypeOf(value).toMatchTypeOf<QueryTag<Unset>>()
expectTypeOf(value).toExtend<QueryTag<Unset>>()
})

test('tag function returns a typed tag when data generic is provided', () => {
const value = tag<string>()

expectTypeOf(value).toMatchTypeOf<QueryTag<string>>()
expectTypeOf(value).toExtend<QueryTag<string>>()
})

test('tag factory returns a typed tag when data generic is provided', () => {
const factory = tag<string, string>((value: string) => value)

expectTypeOf(factory).toMatchTypeOf<QueryTagFactory<string, string>>()
expectTypeOf(factory).toExtend<QueryTagFactory<string, string>>()

const value = factory('foo')

expectTypeOf(value).toMatchTypeOf<QueryTag<string>>()
expectTypeOf(value).toExtend<QueryTag<string>>()
})

test('query from query function with tags callback is called with the query data', () => {
Expand All @@ -41,7 +41,7 @@ test('query from query function with tags callback is called with the query data

query(action, [], {
tags: (data) => {
expectTypeOf(data).toMatchTypeOf<string>()
expectTypeOf(data).toExtend<string>()

return []
},
Expand All @@ -52,9 +52,9 @@ test('query from query composition with tags callback is called with the query d
const { useQuery } = createQueryClient()
const action = vi.fn(() => 'foo')

useQuery(action, [], {
useQuery(action, () => [], {
tags: (data) => {
expectTypeOf(data).toMatchTypeOf<string>()
expectTypeOf(data).toExtend<string>()

return []
},
Expand Down
1 change: 0 additions & 1 deletion src/types/getters.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type MaybeGetter<T> = T | Getter<T>
export type Getter<T> = () => T
4 changes: 2 additions & 2 deletions src/types/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RetryOptions } from '@/utilities/retry'
import { Getter, MaybeGetter } from './getters'
import { Getter } from './getters'
import { QueryTag, Unset } from '@/types/tags'
import { DefaultValue } from './utilities'

Expand All @@ -15,7 +15,7 @@ export type QueryData<

export type QueryActionArgs<
TAction extends QueryAction
> = MaybeGetter<Parameters<TAction>> | Getter<Parameters<TAction> | null> | Getter<null>
> = Getter<Parameters<TAction> | null> | Getter<null>

export type QueryTags<
TAction extends QueryAction = QueryAction
Expand Down