diff --git a/src/atomWithInfiniteQuery.ts b/src/atomWithInfiniteQuery.ts index daffd4a..791f035 100644 --- a/src/atomWithInfiniteQuery.ts +++ b/src/atomWithInfiniteQuery.ts @@ -6,7 +6,7 @@ import { QueryKey, QueryObserver, } from '@tanstack/query-core' -import { Getter } from 'jotai' +import { Atom, Getter } from 'jotai' import { baseAtomWithQuery } from './baseAtomWithQuery' import { queryClientAtom } from './queryClientAtom' import { @@ -34,7 +34,7 @@ export function atomWithInfiniteQuery< TPageParam >, getQueryClient?: (get: Getter) => QueryClient -): AtomWithInfiniteQueryResult +): Atom> export function atomWithInfiniteQuery< TQueryFnData, TError = DefaultError, @@ -52,7 +52,7 @@ export function atomWithInfiniteQuery< TPageParam >, getQueryClient?: (get: Getter) => QueryClient -): DefinedAtomWithInfiniteQueryResult +): Atom> export function atomWithInfiniteQuery< TQueryFnData, TError = DefaultError, @@ -71,7 +71,7 @@ export function atomWithInfiniteQuery< TPageParam >, getQueryClient?: (get: Getter) => QueryClient -): AtomWithInfiniteQueryResult +): Atom> export function atomWithInfiniteQuery( getOptions: (get: Getter) => AtomWithInfiniteQueryOptions, getQueryClient: (get: Getter) => QueryClient = (get) => get(queryClientAtom) diff --git a/src/atomWithMutation.ts b/src/atomWithMutation.ts index 5f052f1..e015633 100644 --- a/src/atomWithMutation.ts +++ b/src/atomWithMutation.ts @@ -4,7 +4,7 @@ import { MutationOptions, QueryClient, } from '@tanstack/query-core' -import { Getter, atom } from 'jotai' +import { Atom, Getter, atom } from 'jotai' import { make, pipe, toObservable } from 'wonka' import { queryClientAtom } from './queryClientAtom' import { AtomWithMutationResult, MutateFunction } from './types' @@ -20,7 +20,7 @@ export function atomWithMutation< get: Getter ) => MutationOptions, getQueryClient: (get: Getter) => QueryClient = (get) => get(queryClientAtom) -): AtomWithMutationResult { +): Atom> { const IN_RENDER = Symbol() const optionsAtom = atom((get) => { diff --git a/src/atomWithQuery.ts b/src/atomWithQuery.ts index ff5edef..b06128b 100644 --- a/src/atomWithQuery.ts +++ b/src/atomWithQuery.ts @@ -4,7 +4,7 @@ import { QueryKey, QueryObserver, } from '@tanstack/query-core' -import { Getter } from 'jotai' +import { Atom, Getter } from 'jotai' import { baseAtomWithQuery } from './baseAtomWithQuery' import { queryClientAtom } from './queryClientAtom' import { @@ -25,7 +25,7 @@ export function atomWithQuery< get: Getter ) => UndefinedInitialDataOptions, getQueryClient?: (get: Getter) => QueryClient -): AtomWithQueryResult +): Atom> export function atomWithQuery< TQueryFnData = unknown, TError = DefaultError, @@ -36,7 +36,7 @@ export function atomWithQuery< get: Getter ) => DefinedInitialDataOptions, getQueryClient?: (get: Getter) => QueryClient -): DefinedAtomWithQueryResult +): Atom> export function atomWithQuery< TQueryFnData = unknown, TError = DefaultError, @@ -47,7 +47,7 @@ export function atomWithQuery< get: Getter ) => AtomWithQueryOptions, getQueryClient?: (get: Getter) => QueryClient -): AtomWithQueryResult +): Atom> export function atomWithQuery( getOptions: (get: Getter) => AtomWithQueryOptions, getQueryClient: (get: Getter) => QueryClient = (get) => get(queryClientAtom) diff --git a/src/atomWithSuspenseInfiniteQuery.ts b/src/atomWithSuspenseInfiniteQuery.ts index 68a24da..399cc67 100644 --- a/src/atomWithSuspenseInfiniteQuery.ts +++ b/src/atomWithSuspenseInfiniteQuery.ts @@ -6,7 +6,7 @@ import { QueryKey, QueryObserver, } from '@tanstack/query-core' -import { Getter, atom } from 'jotai' +import { Atom, Getter, atom } from 'jotai' import { baseAtomWithQuery } from './baseAtomWithQuery' import { queryClientAtom } from './queryClientAtom' import { @@ -33,7 +33,7 @@ export function atomWithSuspenseInfiniteQuery< TPageParam >, getQueryClient: (get: Getter) => QueryClient = (get) => get(queryClientAtom) -): AtomWithSuspenseInfiniteQueryResult { +): Atom> { const suspenseOptionsAtom = atom((get) => { const options = getOptions(get) return { @@ -48,5 +48,5 @@ export function atomWithSuspenseInfiniteQuery< (get: Getter) => get(suspenseOptionsAtom), InfiniteQueryObserver as typeof QueryObserver, getQueryClient - ) as unknown as AtomWithSuspenseInfiniteQueryResult + ) as unknown as Atom> } diff --git a/src/atomWithSuspenseQuery.ts b/src/atomWithSuspenseQuery.ts index e9e0763..8f6c97b 100644 --- a/src/atomWithSuspenseQuery.ts +++ b/src/atomWithSuspenseQuery.ts @@ -4,7 +4,7 @@ import { QueryKey, QueryObserver, } from '@tanstack/query-core' -import { Getter, atom } from 'jotai' +import { Atom, Getter, atom } from 'jotai' import { baseAtomWithQuery } from './baseAtomWithQuery' import { queryClientAtom } from './queryClientAtom' import { @@ -23,7 +23,7 @@ export function atomWithSuspenseQuery< get: Getter ) => AtomWithSuspenseQueryOptions, getQueryClient: (get: Getter) => QueryClient = (get) => get(queryClientAtom) -): AtomWithSuspenseQueryResult { +): Atom> { const suspenseOptions = atom((get) => { const options = getOptions(get) return { @@ -38,5 +38,5 @@ export function atomWithSuspenseQuery< (get: Getter) => get(suspenseOptions), QueryObserver, getQueryClient - ) as AtomWithSuspenseQueryResult + ) as Atom> } diff --git a/src/types.ts b/src/types.ts index c0c6be4..3b0ba06 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,7 +13,6 @@ import { QueryObserverResult, WithRequired, } from '@tanstack/query-core' -import { Atom } from 'jotai' type Override = { [K in keyof A]: K extends keyof B ? B[K] : A[K] } @@ -33,14 +32,13 @@ export type MutateAsyncFunction< TContext = unknown, > = QueryMutateFunction -export type AtomWithMutationResult = Atom< +export type AtomWithMutationResult = Override< MutationObserverResult, { mutate: MutateFunction } > & { mutateAsync: MutateAsyncFunction } -> export interface MutationOptions< TData = unknown, @@ -133,42 +131,40 @@ export interface AtomWithSuspenseInfiniteQueryOptions< 'enabled' | 'throwOnError' | 'placeholderData' > {} -export type AtomWithQueryResult = Atom< - QueryObserverResult -> +export type AtomWithQueryResult< + TData = unknown, + TError = DefaultError, +> = QueryObserverResult export type DefinedAtomWithQueryResult< TData = unknown, TError = DefaultError, -> = Atom> +> = DefinedQueryObserverResult export type AtomWithSuspenseQueryResult< TData = unknown, TError = DefaultError, -> = Atom< +> = | Omit, 'isPlaceholderData'> | Promise< Omit, 'isPlaceholderData'> > -> export type AtomWithInfiniteQueryResult< TData = unknown, TError = DefaultError, -> = Atom> +> = InfiniteQueryObserverResult export type DefinedAtomWithInfiniteQueryResult< TData = unknown, TError = DefaultError, -> = Atom> +> = DefinedInfiniteQueryObserverResult export type AtomWithSuspenseInfiniteQueryResult< TData = unknown, TError = DefaultError, -> = Atom< - Promise< - Omit, 'isPlaceholderData'> - > +> = Promise< + Omit, 'isPlaceholderData'> > export type UndefinedInitialDataOptions<