reactjs 从@react-native-async-storage/异步存储导入异步存储时出错'

6jygbczu  于 2023-03-12  发布在  React
关注(0)|答案(2)|浏览(190)

获取错误消息

Type 'AsyncStorageStatic' is missing the following properties from type 'IAsyncStorage<string, any>': store, size, getStorets(2739

我已经按照安装文档,但仍然错误.

shyt4zoc

shyt4zoc1#

您可以在此文件中找到所需的类型:

~/node_modules/keyvaluestorage/dist/cjs/react-native/types.d.ts

其内容为:

export declare namespace AsyncStorageTypes {
    type Entry<K = string, V = any> = [K, V | null];
    type Entries<K = string, V = any> = Array<Entry<K, V>>;
    type ErrBack<V = any> = (err: Error | null, val?: V | null) => {};
    type ArrErrBack<V = any> = (err: Array<Error> | null, val?: V) => {};
}
export declare abstract class IAsyncStorage<K = string, V = any> {
    abstract store: Map<K, V | null>;
    abstract size(): number;
    abstract getStore(): Map<K, V | null>;
    abstract getItem(k: K, cb?: AsyncStorageTypes.ErrBack<V>): Promise<V | null>;
    abstract setItem(k: K, v: V, cb?: AsyncStorageTypes.ErrBack<V>): Promise<void>;
    abstract removeItem(k: K, cb?: AsyncStorageTypes.ErrBack<V>): Promise<void>;
    abstract clear(cb?: AsyncStorageTypes.ErrBack<V>): Promise<void>;
    abstract getAllKeys(cb?: AsyncStorageTypes.ErrBack<Array<K>>): Promise<Array<K>>;
    abstract multiGet(keys: Array<K>, cb?: AsyncStorageTypes.ErrBack<AsyncStorageTypes.Entries<K, V>>): Promise<AsyncStorageTypes.Entries<K, V>>;
    abstract multiSet(entries: AsyncStorageTypes.Entries<K, V>, cb?: AsyncStorageTypes.ErrBack<V>): Promise<void>;
    abstract multiRemove(keys: Array<K>, cb?: AsyncStorageTypes.ErrBack<V>): Promise<void>;
    abstract mergeItem(key: string, value: string, cb?: AsyncStorageTypes.ErrBack<string>): Promise<void>;
    abstract multiMerge(entries: AsyncStorageTypes.Entries<string, string>, cb?: AsyncStorageTypes.ArrErrBack<string>): Promise<void>;
    abstract flushGetRequests(): any;
}

将其导入或复制到代码中,然后执行以下操作:

<WalletConnectProvider
  storageOptions={{
    asyncStorage: AsyncStorageStatic as unknown as IAsyncStorage,
  }}
>
  <App/>
</WalletConnectProvider>
m528fe3b

m528fe3b2#

有时你需要重新启动你的Android模拟器或停止它,并重新开始新鲜,如果它没有找到类型或模块后,其安装.

相关问题