diff --git a/package.json b/package.json index abcaa79e0..193131369 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "build": "bunchee", "build:e2e": "pnpm next build e2e/site", "attw": "attw --pack", - "types:check": "pnpm -r run types:check", + "types:check": "tsc --noEmit", "prepublishOnly": "pnpm clean && pnpm build", "publish-beta": "pnpm publish --tag beta", "format": "prettier --write ./**/*.{ts,tsx}", diff --git a/src/_internal/types.ts b/src/_internal/types.ts index aa132725f..106e26333 100644 --- a/src/_internal/types.ts +++ b/src/_internal/types.ts @@ -403,7 +403,10 @@ export type SWRConfiguration< Data = any, Error = any, Fn extends BareFetcher = BareFetcher -> = Partial> +> = Partial> & + Partial & { + provider?: (cache: Readonly) => Cache + } export type IsLoadingResponse< Data = any, diff --git a/src/_internal/utils/config-context.ts b/src/_internal/utils/config-context.ts index 0811b30cf..872b332b0 100644 --- a/src/_internal/utils/config-context.ts +++ b/src/_internal/utils/config-context.ts @@ -11,23 +11,15 @@ import { initCache } from './cache' import { mergeConfigs } from './merge-config' import { UNDEFINED, mergeObjects, isFunction } from './shared' import { useIsomorphicLayoutEffect } from './env' -import type { - SWRConfiguration, - FullConfiguration, - ProviderConfiguration, - Cache -} from '../types' - -type Config = SWRConfiguration & - Partial & { - provider?: (cache: Readonly) => Cache - } +import type { SWRConfiguration, FullConfiguration } from '../types' export const SWRConfigContext = createContext>({}) const SWRConfig: FC< PropsWithChildren<{ - value?: Config | ((parentConfig?: Config) => Config) + value?: + | SWRConfiguration + | ((parentConfig?: SWRConfiguration) => SWRConfiguration) }> > = props => { const { value } = props diff --git a/test/type/config.tsx b/test/type/config.tsx index aaa4e545e..aa48c12a2 100644 --- a/test/type/config.tsx +++ b/test/type/config.tsx @@ -157,3 +157,36 @@ export function testFallbackDataConfig() { expectType>(true) expectType>(true) } + +export function testProviderConfig() { + const GlobalSetting = ({ children }: { children: React.ReactNode }) => { + return ( + new Map(), + isOnline() { + /* Customize the network state detector */ + return true + }, + isVisible() { + /* Customize the visibility state detector */ + return true + }, + initFocus(_callback) { + /* Register the listener with your state provider */ + }, + initReconnect(_callback) { + /* Register the listener with your state provider */ + } + }} + > + {children} + + ) + } + return ( + +
+ + ) +}