diff --git a/src/_internal/types.ts b/src/_internal/types.ts index 13c0279cf..c72e2b027 100644 --- a/src/_internal/types.ts +++ b/src/_internal/types.ts @@ -405,6 +405,11 @@ export type SWRConfiguration< Fn extends BareFetcher = BareFetcher > = Partial> +export type IsLoadingResponse< + Data = any, + Options = SWROptions +> = Options extends { suspense: true } ? false : boolean + type SWROptions = SWRConfiguration> export interface SWRResponse { /** @@ -417,7 +422,7 @@ export interface SWRResponse { error: Error | undefined mutate: KeyedMutator isValidating: boolean - isLoading: BlockingData extends true ? false : boolean + isLoading: IsLoadingResponse } export type KeyLoader = diff --git a/test/type/config.tsx b/test/type/config.tsx index 09d725fbb..aaa4e545e 100644 --- a/test/type/config.tsx +++ b/test/type/config.tsx @@ -148,3 +148,12 @@ export function testEmptyConfig() { expectType>(true) expectType>(true) } + +export function testFallbackDataConfig() { + const fetcher = (k: string) => Promise.resolve({ value: k }) + const { data, isLoading } = useSWR('/api', fetcher, { + fallbackData: { value: 'fallback' } + }) + expectType>(true) + expectType>(true) +}