react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Type 'AsyncStorageStatic' is not assignable to type 'AsyncStorage'

Open Joshandrews43 opened this issue 5 years ago • 6 comments

Describe the bug

The typescript type definition of AsyncStorage as provided by @react-native-community/async-storage does not match the typescript type definition of the asyncStorage paramater to the getStorybookUI initialization function.

To Reproduce Steps to reproduce the behavior:

  1. Install @react-native-community/async-storage and storybook in a react native expo project.
  2. Configure storybook as such:
import AsyncStorage from '@react-native-community/async-storage';

configure(() => {
  require('./stories'); // eslint-disable-line global-require
}, module);

const Storybook = getStorybookUI({
  asyncStorage: AsyncStorage,
});

export default Storybook;
  1. There is a type error for the asyncStorage param.

Expected behavior

The parameter should accept the type of the recommended AsyncStorage by react-native, since the one imported from react-native is deprecated.

Screenshots Screen Shot 2020-09-17 at 1 00 08 PM

System:

Environment Info:

  System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
  Binaries:
    Node: 12.18.1 - ~/.nvm/versions/node/v12.18.1/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v12.18.1/bin/npm
  Browsers:
    Chrome: 85.0.4183.102
    Firefox: 72.0.2
    Safari: 13.1
  npmPackages:
    @storybook/react-native: ^5.3.19 => 5.3.21 
    @storybook/react-native-server: ^5.3.19 => 5.3.21 

Joshandrews43 avatar Sep 17 '20 20:09 Joshandrews43

@Joshandrews43 Can you please include the line where you import AsyncStorage so I can see if you are using the default export.

dannyhw avatar Sep 25 '20 21:09 dannyhw

@Joshandrews43 Can you please include the line where you import AsyncStorage so I can see if you are using the default export.

@dannyhw I've updated my code above to reflect this. I am indeed using the default export.

Joshandrews43 avatar Sep 25 '20 22:09 Joshandrews43

@Joshandrews43 I actually did a release of 5.3.23 pretty much just now, might be worth just quickly checking if it's resolved with the latest version since I did make a few changes related to typescript.

dannyhw avatar Sep 25 '20 22:09 dannyhw

@react-native-community/async-storage is Deprecated. devs migrated packages to @react-native-async-storage/async-storage.

ewnu avatar Nov 20 '20 06:11 ewnu

@react-native-community/async-storage is Deprecated. devs migrated packages to @react-native-async-storage/async-storage.

Does that mean this is closed? I was searching the first issue tag..

TurtleWolfe avatar Jun 04 '21 05:06 TurtleWolfe

This prop will no longer be required in 6.0 the @react-native-async-storage/async-storage package will become a dependency instead of being passed as a param.

dannyhw avatar Jun 05 '21 21:06 dannyhw

I would suggest to revert this decision to bundle async-storage with this package. We removed async-storage from our app entirely and using react-mmkv which is much faster and easier to use cause its sync. To have the option to provide the means of persisting state is good software design so the current interface is just fine and I can easily adopt it to react-mmkv

However, there is slight problem:

asyncStorage: {
  getItem(key) {
    return Promise.resolve(mmkv.getStringSetting(key) || null);
  }
  setItem(key, value) {
    return Promise.resolve(mmkv.setStringSetting(key, value));
  }
}

does not work in 5.3.27. The StoryBookUI is not loading stories anymore. Setting the asyncStorage to null makes it work again, but of course no longer persists values.

pke avatar Oct 29 '22 23:10 pke

@pke I'd be happy to take any PRs to make the storage solution optional (new features like this would go to v6 not 5.3). The reason for making it a requirement was just to simplify things.

dannyhw avatar Oct 30 '22 12:10 dannyhw

Sure it could default to the optional dependency of asyncstorage but should be configurable. And believe me, once you tried synced settings you will not go back to async ones ;)

pke avatar Oct 30 '22 18:10 pke

Closing since the async storage option isn't required anymore. A new issue should be made to make the local storage configurable

dannyhw avatar Jul 14 '23 10:07 dannyhw