Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch on SWR Configuration #2881

Closed
samuelhulla opened this issue Jan 25, 2024 · 0 comments · Fixed by #2882
Closed

Type mismatch on SWR Configuration #2881

samuelhulla opened this issue Jan 25, 2024 · 0 comments · Fixed by #2882

Comments

@samuelhulla
Copy link
Contributor

The properties in the react-native section seem no longer compatible with the SWRConfiguration type.

In the docs you have the example of

<SWRConfig
  value={{
    provider: () => 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 */
    }
  }}
>

This however misaligns with the exported type of SWRConfiguration as the following properties are missing

  • provider
  • initFocus
  • initReconnect

Upon further inspection of the exported index.d.ts, the missing properties come from type Config which is however not exported.

type Config = SWRConfiguration & Partial<ProviderConfiguration> & {
    provider?: (cache: Readonly<Cache>) => Cache;
};

where ProviderConfiguration is defined as

type ProviderConfiguration = {
    initFocus: (callback: () => void) => (() => void) | void;
    initReconnect: (callback: () => void) => (() => void) | void;
};

Unless there's an internal reason for not exposing these methods (which seems contradictory with the react-native documentation) the exported type for SWRConfig should be Config instead

Furthermore when importing the component SWRConfig it just defaults to :any, seems a resolution issue with directly importing react over just importing it's types in the SWRConfig definition. import ReactExports from 'react'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant